<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Class: Collection</title>
    
    
    
    
    
    <meta property="og:title" content=""/>
    <meta property="og:type" content="website"/>
    <meta property="og:image" content=""/>
    
    <meta property="og:url" content=""/>
    
    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <script src="scripts/jquery.min.js"></script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="styles/jaguar.css">
    
    
    <script>
    var config = {"monospaceLinks":true,"cleverLinks":true,"default":{"outputSourceFiles":true},"applicationName":"Node.js MongoDB Driver API","googleAnalytics":"UA-29229787-1","openGraph":{"title":"","type":"website","image":"","site_name":"","url":""},"meta":{"title":"","description":"","keyword":""},"linenums":true};
    </script>
    

    
    <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

      ga('create', UA-29229787-1, 'auto');
      ga('send', 'pageview');
    </script>    
    
</head>
<body>
<div id="wrap" class="clearfix" style="width:100%;">
    <table style="height:100%;width:100%">
        <tr>
            <td valign='top' width="1px">
                
<div class="navigation">
    <h3 class="applicationName"><a href="index.html">Node.js MongoDB Driver API</a></h3>

    <div class="search">
        <input id="search" type="text" class="form-control input-sm" placeholder="Search Documentations">
    </div>
    <ul class="list">
    
        <li class="item" data-name="Admin">
            <span class="title">
                <a href="Admin.html">Admin</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="Admin~resultCallback"><a href="Admin.html#~resultCallback">resultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Admin#addUser"><a href="Admin.html#addUser">addUser</a></li>
            
                <li data-name="Admin#authenticate"><a href="Admin.html#authenticate">authenticate</a></li>
            
                <li data-name="Admin#buildInfo"><a href="Admin.html#buildInfo">buildInfo</a></li>
            
                <li data-name="Admin#command"><a href="Admin.html#command">command</a></li>
            
                <li data-name="Admin#listDatabases"><a href="Admin.html#listDatabases">listDatabases</a></li>
            
                <li data-name="Admin#logout"><a href="Admin.html#logout">logout</a></li>
            
                <li data-name="Admin#ping"><a href="Admin.html#ping">ping</a></li>
            
                <li data-name="Admin#profilingInfo"><a href="Admin.html#profilingInfo">profilingInfo</a></li>
            
                <li data-name="Admin#profilingLevel"><a href="Admin.html#profilingLevel">profilingLevel</a></li>
            
                <li data-name="Admin#removeUser"><a href="Admin.html#removeUser">removeUser</a></li>
            
                <li data-name="Admin#replSetGetStatus"><a href="Admin.html#replSetGetStatus">replSetGetStatus</a></li>
            
                <li data-name="Admin#serverInfo"><a href="Admin.html#serverInfo">serverInfo</a></li>
            
                <li data-name="Admin#serverStatus"><a href="Admin.html#serverStatus">serverStatus</a></li>
            
                <li data-name="Admin#setProfilingLevel"><a href="Admin.html#setProfilingLevel">setProfilingLevel</a></li>
            
                <li data-name="Admin#validateCollection"><a href="Admin.html#validateCollection">validateCollection</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="AggregationCursor">
            <span class="title">
                <a href="AggregationCursor.html">AggregationCursor</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="AggregationCursor~endCallback"><a href="AggregationCursor.html#~endCallback">endCallback</a></li>
            
                <li data-name="AggregationCursor~iteratorCallback"><a href="AggregationCursor.html#~iteratorCallback">iteratorCallback</a></li>
            
                <li data-name="AggregationCursor~resultCallback"><a href="AggregationCursor.html#~resultCallback">resultCallback</a></li>
            
                <li data-name="AggregationCursor~toArrayResultCallback"><a href="AggregationCursor.html#~toArrayResultCallback">toArrayResultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="AggregationCursor#batchSize"><a href="AggregationCursor.html#batchSize">batchSize</a></li>
            
                <li data-name="AggregationCursor#clone"><a href="AggregationCursor.html#clone">clone</a></li>
            
                <li data-name="AggregationCursor#close"><a href="AggregationCursor.html#close">close</a></li>
            
                <li data-name="AggregationCursor#each"><a href="AggregationCursor.html#each">each</a></li>
            
                <li data-name="AggregationCursor#explain"><a href="AggregationCursor.html#explain">explain</a></li>
            
                <li data-name="AggregationCursor#geoNear"><a href="AggregationCursor.html#geoNear">geoNear</a></li>
            
                <li data-name="AggregationCursor#group"><a href="AggregationCursor.html#group">group</a></li>
            
                <li data-name="AggregationCursor#hasNext"><a href="AggregationCursor.html#hasNext">hasNext</a></li>
            
                <li data-name="AggregationCursor#isClosed"><a href="AggregationCursor.html#isClosed">isClosed</a></li>
            
                <li data-name="AggregationCursor#limit"><a href="AggregationCursor.html#limit">limit</a></li>
            
                <li data-name="AggregationCursor#lookup"><a href="AggregationCursor.html#lookup">lookup</a></li>
            
                <li data-name="AggregationCursor#match"><a href="AggregationCursor.html#match">match</a></li>
            
                <li data-name="AggregationCursor#maxTimeMS"><a href="AggregationCursor.html#maxTimeMS">maxTimeMS</a></li>
            
                <li data-name="AggregationCursor#next"><a href="AggregationCursor.html#next">next</a></li>
            
                <li data-name="AggregationCursor#out"><a href="AggregationCursor.html#out">out</a></li>
            
                <li data-name="AggregationCursor#pause"><a href="AggregationCursor.html#pause">pause</a></li>
            
                <li data-name="AggregationCursor#pipe"><a href="AggregationCursor.html#pipe">pipe</a></li>
            
                <li data-name="AggregationCursor#project"><a href="AggregationCursor.html#project">project</a></li>
            
                <li data-name="AggregationCursor#read"><a href="AggregationCursor.html#read">read</a></li>
            
                <li data-name="AggregationCursor#redact"><a href="AggregationCursor.html#redact">redact</a></li>
            
                <li data-name="AggregationCursor#resume"><a href="AggregationCursor.html#resume">resume</a></li>
            
                <li data-name="AggregationCursor#rewind"><a href="AggregationCursor.html#rewind">rewind</a></li>
            
                <li data-name="AggregationCursor#setEncoding"><a href="AggregationCursor.html#setEncoding">setEncoding</a></li>
            
                <li data-name="AggregationCursor#skip"><a href="AggregationCursor.html#skip">skip</a></li>
            
                <li data-name="AggregationCursor#sort"><a href="AggregationCursor.html#sort">sort</a></li>
            
                <li data-name="AggregationCursor#toArray"><a href="AggregationCursor.html#toArray">toArray</a></li>
            
                <li data-name="AggregationCursor#unpipe"><a href="AggregationCursor.html#unpipe">unpipe</a></li>
            
                <li data-name="AggregationCursor#unshift"><a href="AggregationCursor.html#unshift">unshift</a></li>
            
                <li data-name="AggregationCursor#unwind"><a href="AggregationCursor.html#unwind">unwind</a></li>
            
                <li data-name="AggregationCursor#wrap"><a href="AggregationCursor.html#wrap">wrap</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="AggregationCursor#event:close"><a href="AggregationCursor.html#event:close">close</a></li>
            
                <li data-name="AggregationCursor#event:data"><a href="AggregationCursor.html#event:data">data</a></li>
            
                <li data-name="AggregationCursor#event:end"><a href="AggregationCursor.html#event:end">end</a></li>
            
                <li data-name="AggregationCursor#event:readable"><a href="AggregationCursor.html#event:readable">readable</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Binary">
            <span class="title">
                <a href="Binary.html">Binary</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="Binary.SUBTYPE_BYTE_ARRAY"><a href="Binary.html#.SUBTYPE_BYTE_ARRAY">SUBTYPE_BYTE_ARRAY</a></li>
            
                <li data-name="Binary.SUBTYPE_DEFAULT"><a href="Binary.html#.SUBTYPE_DEFAULT">SUBTYPE_DEFAULT</a></li>
            
                <li data-name="Binary.SUBTYPE_FUNCTION"><a href="Binary.html#.SUBTYPE_FUNCTION">SUBTYPE_FUNCTION</a></li>
            
                <li data-name="Binary.SUBTYPE_MD5"><a href="Binary.html#.SUBTYPE_MD5">SUBTYPE_MD5</a></li>
            
                <li data-name="Binary.SUBTYPE_USER_DEFINED"><a href="Binary.html#.SUBTYPE_USER_DEFINED">SUBTYPE_USER_DEFINED</a></li>
            
                <li data-name="Binary.SUBTYPE_UUID"><a href="Binary.html#.SUBTYPE_UUID">SUBTYPE_UUID</a></li>
            
                <li data-name="Binary.SUBTYPE_UUID_OLD"><a href="Binary.html#.SUBTYPE_UUID_OLD">SUBTYPE_UUID_OLD</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Binary#length"><a href="Binary.html#length">length</a></li>
            
                <li data-name="Binary#put"><a href="Binary.html#put">put</a></li>
            
                <li data-name="Binary#read"><a href="Binary.html#read">read</a></li>
            
                <li data-name="Binary#value"><a href="Binary.html#value">value</a></li>
            
                <li data-name="Binary#write"><a href="Binary.html#write">write</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="BSONRegExp">
            <span class="title">
                <a href="BSONRegExp.html">BSONRegExp</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="BulkWriteResult">
            <span class="title">
                <a href="BulkWriteResult.html">BulkWriteResult</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="BulkWriteResult#getInsertedIds"><a href="BulkWriteResult.html#getInsertedIds">getInsertedIds</a></li>
            
                <li data-name="BulkWriteResult#getLastOp"><a href="BulkWriteResult.html#getLastOp">getLastOp</a></li>
            
                <li data-name="BulkWriteResult#getRawResponse"><a href="BulkWriteResult.html#getRawResponse">getRawResponse</a></li>
            
                <li data-name="BulkWriteResult#getUpsertedIdAt"><a href="BulkWriteResult.html#getUpsertedIdAt">getUpsertedIdAt</a></li>
            
                <li data-name="BulkWriteResult#getUpsertedIds"><a href="BulkWriteResult.html#getUpsertedIds">getUpsertedIds</a></li>
            
                <li data-name="BulkWriteResult#getWriteConcernError"><a href="BulkWriteResult.html#getWriteConcernError">getWriteConcernError</a></li>
            
                <li data-name="BulkWriteResult#getWriteErrorAt"><a href="BulkWriteResult.html#getWriteErrorAt">getWriteErrorAt</a></li>
            
                <li data-name="BulkWriteResult#getWriteErrorCount"><a href="BulkWriteResult.html#getWriteErrorCount">getWriteErrorCount</a></li>
            
                <li data-name="BulkWriteResult#getWriteErrors"><a href="BulkWriteResult.html#getWriteErrors">getWriteErrors</a></li>
            
                <li data-name="BulkWriteResult#hasWriteErrors"><a href="BulkWriteResult.html#hasWriteErrors">hasWriteErrors</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Code">
            <span class="title">
                <a href="Code.html">Code</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Collection">
            <span class="title">
                <a href="Collection.html">Collection</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="Collection~bulkWriteOpCallback"><a href="Collection.html#~bulkWriteOpCallback">bulkWriteOpCallback</a></li>
            
                <li data-name="Collection~BulkWriteOpResult"><a href="Collection.html#~BulkWriteOpResult">BulkWriteOpResult</a></li>
            
                <li data-name="Collection~collectionResultCallback"><a href="Collection.html#~collectionResultCallback">collectionResultCallback</a></li>
            
                <li data-name="Collection~countCallback"><a href="Collection.html#~countCallback">countCallback</a></li>
            
                <li data-name="Collection~deleteWriteOpCallback"><a href="Collection.html#~deleteWriteOpCallback">deleteWriteOpCallback</a></li>
            
                <li data-name="Collection~deleteWriteOpResult"><a href="Collection.html#~deleteWriteOpResult">deleteWriteOpResult</a></li>
            
                <li data-name="Collection~findAndModifyCallback"><a href="Collection.html#~findAndModifyCallback">findAndModifyCallback</a></li>
            
                <li data-name="Collection~findAndModifyWriteOpResult"><a href="Collection.html#~findAndModifyWriteOpResult">findAndModifyWriteOpResult</a></li>
            
                <li data-name="Collection~insertOneWriteOpCallback"><a href="Collection.html#~insertOneWriteOpCallback">insertOneWriteOpCallback</a></li>
            
                <li data-name="Collection~insertOneWriteOpResult"><a href="Collection.html#~insertOneWriteOpResult">insertOneWriteOpResult</a></li>
            
                <li data-name="Collection~insertWriteOpCallback"><a href="Collection.html#~insertWriteOpCallback">insertWriteOpCallback</a></li>
            
                <li data-name="Collection~insertWriteOpResult"><a href="Collection.html#~insertWriteOpResult">insertWriteOpResult</a></li>
            
                <li data-name="Collection~parallelCollectionScanCallback"><a href="Collection.html#~parallelCollectionScanCallback">parallelCollectionScanCallback</a></li>
            
                <li data-name="Collection~resultCallback"><a href="Collection.html#~resultCallback">resultCallback</a></li>
            
                <li data-name="Collection~updateWriteOpCallback"><a href="Collection.html#~updateWriteOpCallback">updateWriteOpCallback</a></li>
            
                <li data-name="Collection~updateWriteOpResult"><a href="Collection.html#~updateWriteOpResult">updateWriteOpResult</a></li>
            
                <li data-name="Collection~writeOpCallback"><a href="Collection.html#~writeOpCallback">writeOpCallback</a></li>
            
                <li data-name="Collection~WriteOpResult"><a href="Collection.html#~WriteOpResult">WriteOpResult</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Collection#aggregate"><a href="Collection.html#aggregate">aggregate</a></li>
            
                <li data-name="Collection#bulkWrite"><a href="Collection.html#bulkWrite">bulkWrite</a></li>
            
                <li data-name="Collection#count"><a href="Collection.html#count">count</a></li>
            
                <li data-name="Collection#createIndex"><a href="Collection.html#createIndex">createIndex</a></li>
            
                <li data-name="Collection#createIndexes"><a href="Collection.html#createIndexes">createIndexes</a></li>
            
                <li data-name="Collection#deleteMany"><a href="Collection.html#deleteMany">deleteMany</a></li>
            
                <li data-name="Collection#deleteOne"><a href="Collection.html#deleteOne">deleteOne</a></li>
            
                <li data-name="Collection#distinct"><a href="Collection.html#distinct">distinct</a></li>
            
                <li data-name="Collection#drop"><a href="Collection.html#drop">drop</a></li>
            
                <li data-name="Collection#dropAllIndexes"><a href="Collection.html#dropAllIndexes">dropAllIndexes</a></li>
            
                <li data-name="Collection#dropIndex"><a href="Collection.html#dropIndex">dropIndex</a></li>
            
                <li data-name="Collection#dropIndexes"><a href="Collection.html#dropIndexes">dropIndexes</a></li>
            
                <li data-name="Collection#ensureIndex"><a href="Collection.html#ensureIndex">ensureIndex</a></li>
            
                <li data-name="Collection#find"><a href="Collection.html#find">find</a></li>
            
                <li data-name="Collection#findAndModify"><a href="Collection.html#findAndModify">findAndModify</a></li>
            
                <li data-name="Collection#findAndRemove"><a href="Collection.html#findAndRemove">findAndRemove</a></li>
            
                <li data-name="Collection#findOne"><a href="Collection.html#findOne">findOne</a></li>
            
                <li data-name="Collection#findOneAndDelete"><a href="Collection.html#findOneAndDelete">findOneAndDelete</a></li>
            
                <li data-name="Collection#findOneAndReplace"><a href="Collection.html#findOneAndReplace">findOneAndReplace</a></li>
            
                <li data-name="Collection#findOneAndUpdate"><a href="Collection.html#findOneAndUpdate">findOneAndUpdate</a></li>
            
                <li data-name="Collection#geoHaystackSearch"><a href="Collection.html#geoHaystackSearch">geoHaystackSearch</a></li>
            
                <li data-name="Collection#geoNear"><a href="Collection.html#geoNear">geoNear</a></li>
            
                <li data-name="Collection#group"><a href="Collection.html#group">group</a></li>
            
                <li data-name="Collection#indexes"><a href="Collection.html#indexes">indexes</a></li>
            
                <li data-name="Collection#indexExists"><a href="Collection.html#indexExists">indexExists</a></li>
            
                <li data-name="Collection#indexInformation"><a href="Collection.html#indexInformation">indexInformation</a></li>
            
                <li data-name="Collection#initializeOrderedBulkOp"><a href="Collection.html#initializeOrderedBulkOp">initializeOrderedBulkOp</a></li>
            
                <li data-name="Collection#initializeUnorderedBulkOp"><a href="Collection.html#initializeUnorderedBulkOp">initializeUnorderedBulkOp</a></li>
            
                <li data-name="Collection#insert"><a href="Collection.html#insert">insert</a></li>
            
                <li data-name="Collection#insertMany"><a href="Collection.html#insertMany">insertMany</a></li>
            
                <li data-name="Collection#insertOne"><a href="Collection.html#insertOne">insertOne</a></li>
            
                <li data-name="Collection#isCapped"><a href="Collection.html#isCapped">isCapped</a></li>
            
                <li data-name="Collection#listIndexes"><a href="Collection.html#listIndexes">listIndexes</a></li>
            
                <li data-name="Collection#mapReduce"><a href="Collection.html#mapReduce">mapReduce</a></li>
            
                <li data-name="Collection#options"><a href="Collection.html#options">options</a></li>
            
                <li data-name="Collection#parallelCollectionScan"><a href="Collection.html#parallelCollectionScan">parallelCollectionScan</a></li>
            
                <li data-name="Collection#reIndex"><a href="Collection.html#reIndex">reIndex</a></li>
            
                <li data-name="Collection#remove"><a href="Collection.html#remove">remove</a></li>
            
                <li data-name="Collection#rename"><a href="Collection.html#rename">rename</a></li>
            
                <li data-name="Collection#replaceOne"><a href="Collection.html#replaceOne">replaceOne</a></li>
            
                <li data-name="Collection#save"><a href="Collection.html#save">save</a></li>
            
                <li data-name="Collection#stats"><a href="Collection.html#stats">stats</a></li>
            
                <li data-name="Collection#update"><a href="Collection.html#update">update</a></li>
            
                <li data-name="Collection#updateMany"><a href="Collection.html#updateMany">updateMany</a></li>
            
                <li data-name="Collection#updateOne"><a href="Collection.html#updateOne">updateOne</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="CommandCursor">
            <span class="title">
                <a href="CommandCursor.html">CommandCursor</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="CommandCursor~endCallback"><a href="CommandCursor.html#~endCallback">endCallback</a></li>
            
                <li data-name="CommandCursor~iteratorCallback"><a href="CommandCursor.html#~iteratorCallback">iteratorCallback</a></li>
            
                <li data-name="CommandCursor~resultCallback"><a href="CommandCursor.html#~resultCallback">resultCallback</a></li>
            
                <li data-name="CommandCursor~toArrayResultCallback"><a href="CommandCursor.html#~toArrayResultCallback">toArrayResultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="CommandCursor#batchSize"><a href="CommandCursor.html#batchSize">batchSize</a></li>
            
                <li data-name="CommandCursor#clone"><a href="CommandCursor.html#clone">clone</a></li>
            
                <li data-name="CommandCursor#close"><a href="CommandCursor.html#close">close</a></li>
            
                <li data-name="CommandCursor#each"><a href="CommandCursor.html#each">each</a></li>
            
                <li data-name="CommandCursor#hasNext"><a href="CommandCursor.html#hasNext">hasNext</a></li>
            
                <li data-name="CommandCursor#isClosed"><a href="CommandCursor.html#isClosed">isClosed</a></li>
            
                <li data-name="CommandCursor#maxTimeMS"><a href="CommandCursor.html#maxTimeMS">maxTimeMS</a></li>
            
                <li data-name="CommandCursor#next"><a href="CommandCursor.html#next">next</a></li>
            
                <li data-name="CommandCursor#pause"><a href="CommandCursor.html#pause">pause</a></li>
            
                <li data-name="CommandCursor#pipe"><a href="CommandCursor.html#pipe">pipe</a></li>
            
                <li data-name="CommandCursor#read"><a href="CommandCursor.html#read">read</a></li>
            
                <li data-name="CommandCursor#resume"><a href="CommandCursor.html#resume">resume</a></li>
            
                <li data-name="CommandCursor#rewind"><a href="CommandCursor.html#rewind">rewind</a></li>
            
                <li data-name="CommandCursor#setEncoding"><a href="CommandCursor.html#setEncoding">setEncoding</a></li>
            
                <li data-name="CommandCursor#setReadPreference"><a href="CommandCursor.html#setReadPreference">setReadPreference</a></li>
            
                <li data-name="CommandCursor#toArray"><a href="CommandCursor.html#toArray">toArray</a></li>
            
                <li data-name="CommandCursor#unpipe"><a href="CommandCursor.html#unpipe">unpipe</a></li>
            
                <li data-name="CommandCursor#unshift"><a href="CommandCursor.html#unshift">unshift</a></li>
            
                <li data-name="CommandCursor#wrap"><a href="CommandCursor.html#wrap">wrap</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="CommandCursor#event:close"><a href="CommandCursor.html#event:close">close</a></li>
            
                <li data-name="CommandCursor#event:data"><a href="CommandCursor.html#event:data">data</a></li>
            
                <li data-name="CommandCursor#event:end"><a href="CommandCursor.html#event:end">end</a></li>
            
                <li data-name="CommandCursor#event:readable"><a href="CommandCursor.html#event:readable">readable</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Cursor">
            <span class="title">
                <a href="Cursor.html">Cursor</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="Cursor~countResultCallback"><a href="Cursor.html#~countResultCallback">countResultCallback</a></li>
            
                <li data-name="Cursor~endCallback"><a href="Cursor.html#~endCallback">endCallback</a></li>
            
                <li data-name="Cursor~iteratorCallback"><a href="Cursor.html#~iteratorCallback">iteratorCallback</a></li>
            
                <li data-name="Cursor~resultCallback"><a href="Cursor.html#~resultCallback">resultCallback</a></li>
            
                <li data-name="Cursor~toArrayResultCallback"><a href="Cursor.html#~toArrayResultCallback">toArrayResultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Cursor#addCursorFlag"><a href="Cursor.html#addCursorFlag">addCursorFlag</a></li>
            
                <li data-name="Cursor#addQueryModifier"><a href="Cursor.html#addQueryModifier">addQueryModifier</a></li>
            
                <li data-name="Cursor#batchSize"><a href="Cursor.html#batchSize">batchSize</a></li>
            
                <li data-name="Cursor#clone"><a href="Cursor.html#clone">clone</a></li>
            
                <li data-name="Cursor#close"><a href="Cursor.html#close">close</a></li>
            
                <li data-name="Cursor#collation"><a href="Cursor.html#collation">collation</a></li>
            
                <li data-name="Cursor#comment"><a href="Cursor.html#comment">comment</a></li>
            
                <li data-name="Cursor#count"><a href="Cursor.html#count">count</a></li>
            
                <li data-name="Cursor#each"><a href="Cursor.html#each">each</a></li>
            
                <li data-name="Cursor#explain"><a href="Cursor.html#explain">explain</a></li>
            
                <li data-name="Cursor#filter"><a href="Cursor.html#filter">filter</a></li>
            
                <li data-name="Cursor#forEach"><a href="Cursor.html#forEach">forEach</a></li>
            
                <li data-name="Cursor#hasNext"><a href="Cursor.html#hasNext">hasNext</a></li>
            
                <li data-name="Cursor#hint"><a href="Cursor.html#hint">hint</a></li>
            
                <li data-name="Cursor#isClosed"><a href="Cursor.html#isClosed">isClosed</a></li>
            
                <li data-name="Cursor#limit"><a href="Cursor.html#limit">limit</a></li>
            
                <li data-name="Cursor#map"><a href="Cursor.html#map">map</a></li>
            
                <li data-name="Cursor#max"><a href="Cursor.html#max">max</a></li>
            
                <li data-name="Cursor#maxAwaitTimeMS"><a href="Cursor.html#maxAwaitTimeMS">maxAwaitTimeMS</a></li>
            
                <li data-name="Cursor#maxScan"><a href="Cursor.html#maxScan">maxScan</a></li>
            
                <li data-name="Cursor#maxTimeMS"><a href="Cursor.html#maxTimeMS">maxTimeMS</a></li>
            
                <li data-name="Cursor#min"><a href="Cursor.html#min">min</a></li>
            
                <li data-name="Cursor#next"><a href="Cursor.html#next">next</a></li>
            
                <li data-name="Cursor#nextObject"><a href="Cursor.html#nextObject">nextObject</a></li>
            
                <li data-name="Cursor#pause"><a href="Cursor.html#pause">pause</a></li>
            
                <li data-name="Cursor#pipe"><a href="Cursor.html#pipe">pipe</a></li>
            
                <li data-name="Cursor#project"><a href="Cursor.html#project">project</a></li>
            
                <li data-name="Cursor#read"><a href="Cursor.html#read">read</a></li>
            
                <li data-name="Cursor#resume"><a href="Cursor.html#resume">resume</a></li>
            
                <li data-name="Cursor#returnKey"><a href="Cursor.html#returnKey">returnKey</a></li>
            
                <li data-name="Cursor#rewind"><a href="Cursor.html#rewind">rewind</a></li>
            
                <li data-name="Cursor#setCursorOption"><a href="Cursor.html#setCursorOption">setCursorOption</a></li>
            
                <li data-name="Cursor#setEncoding"><a href="Cursor.html#setEncoding">setEncoding</a></li>
            
                <li data-name="Cursor#setReadPreference"><a href="Cursor.html#setReadPreference">setReadPreference</a></li>
            
                <li data-name="Cursor#showRecordId"><a href="Cursor.html#showRecordId">showRecordId</a></li>
            
                <li data-name="Cursor#skip"><a href="Cursor.html#skip">skip</a></li>
            
                <li data-name="Cursor#snapshot"><a href="Cursor.html#snapshot">snapshot</a></li>
            
                <li data-name="Cursor#sort"><a href="Cursor.html#sort">sort</a></li>
            
                <li data-name="Cursor#stream"><a href="Cursor.html#stream">stream</a></li>
            
                <li data-name="Cursor#toArray"><a href="Cursor.html#toArray">toArray</a></li>
            
                <li data-name="Cursor#unpipe"><a href="Cursor.html#unpipe">unpipe</a></li>
            
                <li data-name="Cursor#unshift"><a href="Cursor.html#unshift">unshift</a></li>
            
                <li data-name="Cursor#wrap"><a href="Cursor.html#wrap">wrap</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="Cursor#event:close"><a href="Cursor.html#event:close">close</a></li>
            
                <li data-name="Cursor#event:data"><a href="Cursor.html#event:data">data</a></li>
            
                <li data-name="Cursor#event:end"><a href="Cursor.html#event:end">end</a></li>
            
                <li data-name="Cursor#event:readable"><a href="Cursor.html#event:readable">readable</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Db">
            <span class="title">
                <a href="Db.html">Db</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="Db~collectionResultCallback"><a href="Db.html#~collectionResultCallback">collectionResultCallback</a></li>
            
                <li data-name="Db~collectionsResultCallback"><a href="Db.html#~collectionsResultCallback">collectionsResultCallback</a></li>
            
                <li data-name="Db~noResultCallback"><a href="Db.html#~noResultCallback">noResultCallback</a></li>
            
                <li data-name="Db~openCallback"><a href="Db.html#~openCallback">openCallback</a></li>
            
                <li data-name="Db~resultCallback"><a href="Db.html#~resultCallback">resultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Db#addUser"><a href="Db.html#addUser">addUser</a></li>
            
                <li data-name="Db#admin"><a href="Db.html#admin">admin</a></li>
            
                <li data-name="Db#authenticate"><a href="Db.html#authenticate">authenticate</a></li>
            
                <li data-name="Db#close"><a href="Db.html#close">close</a></li>
            
                <li data-name="Db#collection"><a href="Db.html#collection">collection</a></li>
            
                <li data-name="Db#collections"><a href="Db.html#collections">collections</a></li>
            
                <li data-name="Db#command"><a href="Db.html#command">command</a></li>
            
                <li data-name="Db#createCollection"><a href="Db.html#createCollection">createCollection</a></li>
            
                <li data-name="Db#createIndex"><a href="Db.html#createIndex">createIndex</a></li>
            
                <li data-name="Db#db"><a href="Db.html#db">db</a></li>
            
                <li data-name="Db#dropCollection"><a href="Db.html#dropCollection">dropCollection</a></li>
            
                <li data-name="Db#dropDatabase"><a href="Db.html#dropDatabase">dropDatabase</a></li>
            
                <li data-name="Db#ensureIndex"><a href="Db.html#ensureIndex">ensureIndex</a></li>
            
                <li data-name="Db#eval"><a href="Db.html#eval">eval</a></li>
            
                <li data-name="Db#executeDbAdminCommand"><a href="Db.html#executeDbAdminCommand">executeDbAdminCommand</a></li>
            
                <li data-name="Db#indexInformation"><a href="Db.html#indexInformation">indexInformation</a></li>
            
                <li data-name="Db#listCollections"><a href="Db.html#listCollections">listCollections</a></li>
            
                <li data-name="Db#logout"><a href="Db.html#logout">logout</a></li>
            
                <li data-name="Db#open"><a href="Db.html#open">open</a></li>
            
                <li data-name="Db#removeUser"><a href="Db.html#removeUser">removeUser</a></li>
            
                <li data-name="Db#renameCollection"><a href="Db.html#renameCollection">renameCollection</a></li>
            
                <li data-name="Db#stats"><a href="Db.html#stats">stats</a></li>
            
                <li data-name="Db#unref"><a href="Db.html#unref">unref</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="Db#event:authenticated"><a href="Db.html#event:authenticated">authenticated</a></li>
            
                <li data-name="Db#event:close"><a href="Db.html#event:close">close</a></li>
            
                <li data-name="Db#event:error"><a href="Db.html#event:error">error</a></li>
            
                <li data-name="Db#event:fullsetup"><a href="Db.html#event:fullsetup">fullsetup</a></li>
            
                <li data-name="Db#event:parseError"><a href="Db.html#event:parseError">parseError</a></li>
            
                <li data-name="Db#event:reconnect"><a href="Db.html#event:reconnect">reconnect</a></li>
            
                <li data-name="Db#event:timeout"><a href="Db.html#event:timeout">timeout</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="DBRef">
            <span class="title">
                <a href="DBRef.html">DBRef</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Decimal128">
            <span class="title">
                <a href="Decimal128.html">Decimal128</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Decimal128#toString"><a href="Decimal128.html#toString">toString</a></li>
            
                <li data-name="Decimal128.fromString"><a href="Decimal128.html#.fromString">fromString</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Double">
            <span class="title">
                <a href="Double.html">Double</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Double#valueOf"><a href="Double.html#valueOf">valueOf</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="FindOperatorsOrdered">
            <span class="title">
                <a href="FindOperatorsOrdered.html">FindOperatorsOrdered</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="FindOperatorsOrdered#delete"><a href="FindOperatorsOrdered.html#delete">delete</a></li>
            
                <li data-name="FindOperatorsOrdered#deleteOne"><a href="FindOperatorsOrdered.html#deleteOne">deleteOne</a></li>
            
                <li data-name="FindOperatorsOrdered#replaceOne"><a href="FindOperatorsOrdered.html#replaceOne">replaceOne</a></li>
            
                <li data-name="FindOperatorsOrdered#update"><a href="FindOperatorsOrdered.html#update">update</a></li>
            
                <li data-name="FindOperatorsOrdered#updateOne"><a href="FindOperatorsOrdered.html#updateOne">updateOne</a></li>
            
                <li data-name="FindOperatorsOrdered#upsert"><a href="FindOperatorsOrdered.html#upsert">upsert</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="FindOperatorsUnordered">
            <span class="title">
                <a href="FindOperatorsUnordered.html">FindOperatorsUnordered</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="FindOperatorsUnordered#remove"><a href="FindOperatorsUnordered.html#remove">remove</a></li>
            
                <li data-name="FindOperatorsUnordered#removeOne"><a href="FindOperatorsUnordered.html#removeOne">removeOne</a></li>
            
                <li data-name="FindOperatorsUnordered#replaceOne"><a href="FindOperatorsUnordered.html#replaceOne">replaceOne</a></li>
            
                <li data-name="FindOperatorsUnordered#update"><a href="FindOperatorsUnordered.html#update">update</a></li>
            
                <li data-name="FindOperatorsUnordered#updateOne"><a href="FindOperatorsUnordered.html#updateOne">updateOne</a></li>
            
                <li data-name="FindOperatorsUnordered#upsert"><a href="FindOperatorsUnordered.html#upsert">upsert</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="GridFSBucket">
            <span class="title">
                <a href="GridFSBucket.html">GridFSBucket</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="GridFSBucket~errorCallback"><a href="GridFSBucket.html#~errorCallback">errorCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="GridFSBucket#delete"><a href="GridFSBucket.html#delete">delete</a></li>
            
                <li data-name="GridFSBucket#drop"><a href="GridFSBucket.html#drop">drop</a></li>
            
                <li data-name="GridFSBucket#find"><a href="GridFSBucket.html#find">find</a></li>
            
                <li data-name="GridFSBucket#openDownloadStream"><a href="GridFSBucket.html#openDownloadStream">openDownloadStream</a></li>
            
                <li data-name="GridFSBucket#openDownloadStreamByName"><a href="GridFSBucket.html#openDownloadStreamByName">openDownloadStreamByName</a></li>
            
                <li data-name="GridFSBucket#openUploadStream"><a href="GridFSBucket.html#openUploadStream">openUploadStream</a></li>
            
                <li data-name="GridFSBucket#openUploadStreamWithId"><a href="GridFSBucket.html#openUploadStreamWithId">openUploadStreamWithId</a></li>
            
                <li data-name="GridFSBucket#rename"><a href="GridFSBucket.html#rename">rename</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="GridFSBucket#event:index"><a href="GridFSBucket.html#event:index">index</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="GridFSBucketReadStream">
            <span class="title">
                <a href="GridFSBucketReadStream.html">GridFSBucketReadStream</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="GridFSBucketReadStream#_read"><a href="GridFSBucketReadStream.html#_read">_read</a></li>
            
                <li data-name="GridFSBucketReadStream#abort"><a href="GridFSBucketReadStream.html#abort">abort</a></li>
            
                <li data-name="GridFSBucketReadStream#end"><a href="GridFSBucketReadStream.html#end">end</a></li>
            
                <li data-name="GridFSBucketReadStream#start"><a href="GridFSBucketReadStream.html#start">start</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="GridFSBucketReadStream#event:close"><a href="GridFSBucketReadStream.html#event:close">close</a></li>
            
                <li data-name="GridFSBucketReadStream#event:data"><a href="GridFSBucketReadStream.html#event:data">data</a></li>
            
                <li data-name="GridFSBucketReadStream#event:end"><a href="GridFSBucketReadStream.html#event:end">end</a></li>
            
                <li data-name="GridFSBucketReadStream#event:error"><a href="GridFSBucketReadStream.html#event:error">error</a></li>
            
                <li data-name="GridFSBucketReadStream#event:file"><a href="GridFSBucketReadStream.html#event:file">file</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="GridFSBucketWriteStream">
            <span class="title">
                <a href="GridFSBucketWriteStream.html">GridFSBucketWriteStream</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="GridFSBucketWriteStream#abort"><a href="GridFSBucketWriteStream.html#abort">abort</a></li>
            
                <li data-name="GridFSBucketWriteStream#end"><a href="GridFSBucketWriteStream.html#end">end</a></li>
            
                <li data-name="GridFSBucketWriteStream#write"><a href="GridFSBucketWriteStream.html#write">write</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="GridFSBucketWriteStream#event:error"><a href="GridFSBucketWriteStream.html#event:error">error</a></li>
            
                <li data-name="GridFSBucketWriteStream#event:finish"><a href="GridFSBucketWriteStream.html#event:finish">finish</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="GridStore">
            <span class="title">
                <a href="GridStore.html">GridStore</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="GridStore.DEFAULT_CONTENT_TYPE"><a href="GridStore.html#.DEFAULT_CONTENT_TYPE">DEFAULT_CONTENT_TYPE</a></li>
            
                <li data-name="GridStore.DEFAULT_ROOT_COLLECTION"><a href="GridStore.html#.DEFAULT_ROOT_COLLECTION">DEFAULT_ROOT_COLLECTION</a></li>
            
                <li data-name="GridStore.IO_SEEK_CUR"><a href="GridStore.html#.IO_SEEK_CUR">IO_SEEK_CUR</a></li>
            
                <li data-name="GridStore.IO_SEEK_END"><a href="GridStore.html#.IO_SEEK_END">IO_SEEK_END</a></li>
            
                <li data-name="GridStore.IO_SEEK_SET"><a href="GridStore.html#.IO_SEEK_SET">IO_SEEK_SET</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="GridStore~collectionCallback"><a href="GridStore.html#~collectionCallback">collectionCallback</a></li>
            
                <li data-name="GridStore~gridStoreCallback"><a href="GridStore.html#~gridStoreCallback">gridStoreCallback</a></li>
            
                <li data-name="GridStore~openCallback"><a href="GridStore.html#~openCallback">openCallback</a></li>
            
                <li data-name="GridStore~readCallback"><a href="GridStore.html#~readCallback">readCallback</a></li>
            
                <li data-name="GridStore~readlinesCallback"><a href="GridStore.html#~readlinesCallback">readlinesCallback</a></li>
            
                <li data-name="GridStore~resultCallback"><a href="GridStore.html#~resultCallback">resultCallback</a></li>
            
                <li data-name="GridStore~tellCallback"><a href="GridStore.html#~tellCallback">tellCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="GridStore.exist"><a href="GridStore.html#.exist">exist</a></li>
            
                <li data-name="GridStore.list"><a href="GridStore.html#.list">list</a></li>
            
                <li data-name="GridStore.read"><a href="GridStore.html#.read">read</a></li>
            
                <li data-name="GridStore.readlines"><a href="GridStore.html#.readlines">readlines</a></li>
            
                <li data-name="GridStore.unlink"><a href="GridStore.html#.unlink">unlink</a></li>
            
                <li data-name="GridStore#chunkCollection"><a href="GridStore.html#chunkCollection">chunkCollection</a></li>
            
                <li data-name="GridStore#close"><a href="GridStore.html#close">close</a></li>
            
                <li data-name="GridStore#collection"><a href="GridStore.html#collection">collection</a></li>
            
                <li data-name="GridStore#destroy"><a href="GridStore.html#destroy">destroy</a></li>
            
                <li data-name="GridStore#eof"><a href="GridStore.html#eof">eof</a></li>
            
                <li data-name="GridStore#getc"><a href="GridStore.html#getc">getc</a></li>
            
                <li data-name="GridStore#open"><a href="GridStore.html#open">open</a></li>
            
                <li data-name="GridStore#puts"><a href="GridStore.html#puts">puts</a></li>
            
                <li data-name="GridStore#read"><a href="GridStore.html#read">read</a></li>
            
                <li data-name="GridStore#readlines"><a href="GridStore.html#readlines">readlines</a></li>
            
                <li data-name="GridStore#rewind"><a href="GridStore.html#rewind">rewind</a></li>
            
                <li data-name="GridStore#seek"><a href="GridStore.html#seek">seek</a></li>
            
                <li data-name="GridStore#stream"><a href="GridStore.html#stream">stream</a></li>
            
                <li data-name="GridStore#tell"><a href="GridStore.html#tell">tell</a></li>
            
                <li data-name="GridStore#unlink"><a href="GridStore.html#unlink">unlink</a></li>
            
                <li data-name="GridStore#write"><a href="GridStore.html#write">write</a></li>
            
                <li data-name="GridStore#writeFile"><a href="GridStore.html#writeFile">writeFile</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="GridStoreStream">
            <span class="title">
                <a href="GridStoreStream.html">GridStoreStream</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="GridStoreStream#end"><a href="GridStoreStream.html#end">end</a></li>
            
                <li data-name="GridStoreStream#pause"><a href="GridStoreStream.html#pause">pause</a></li>
            
                <li data-name="GridStoreStream#pipe"><a href="GridStoreStream.html#pipe">pipe</a></li>
            
                <li data-name="GridStoreStream#read"><a href="GridStoreStream.html#read">read</a></li>
            
                <li data-name="GridStoreStream#resume"><a href="GridStoreStream.html#resume">resume</a></li>
            
                <li data-name="GridStoreStream#setEncoding"><a href="GridStoreStream.html#setEncoding">setEncoding</a></li>
            
                <li data-name="GridStoreStream#unpipe"><a href="GridStoreStream.html#unpipe">unpipe</a></li>
            
                <li data-name="GridStoreStream#unshift"><a href="GridStoreStream.html#unshift">unshift</a></li>
            
                <li data-name="GridStoreStream#wrap"><a href="GridStoreStream.html#wrap">wrap</a></li>
            
                <li data-name="GridStoreStream#write"><a href="GridStoreStream.html#write">write</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="GridStoreStream#event:close"><a href="GridStoreStream.html#event:close">close</a></li>
            
                <li data-name="GridStoreStream#event:data"><a href="GridStoreStream.html#event:data">data</a></li>
            
                <li data-name="GridStoreStream#event:drain"><a href="GridStoreStream.html#event:drain">drain</a></li>
            
                <li data-name="GridStoreStream#event:end"><a href="GridStoreStream.html#event:end">end</a></li>
            
                <li data-name="GridStoreStream#event:error"><a href="GridStoreStream.html#event:error">error</a></li>
            
                <li data-name="GridStoreStream#event:finish"><a href="GridStoreStream.html#event:finish">finish</a></li>
            
                <li data-name="GridStoreStream#event:pipe"><a href="GridStoreStream.html#event:pipe">pipe</a></li>
            
                <li data-name="GridStoreStream#event:readable"><a href="GridStoreStream.html#event:readable">readable</a></li>
            
                <li data-name="GridStoreStream#event:unpipe"><a href="GridStoreStream.html#event:unpipe">unpipe</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Int32">
            <span class="title">
                <a href="Int32.html">Int32</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Int32#valueOf"><a href="Int32.html#valueOf">valueOf</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Logger">
            <span class="title">
                <a href="Logger.html">Logger</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Logger.currentLogger"><a href="Logger.html#.currentLogger">currentLogger</a></li>
            
                <li data-name="Logger.filter"><a href="Logger.html#.filter">filter</a></li>
            
                <li data-name="Logger.reset"><a href="Logger.html#.reset">reset</a></li>
            
                <li data-name="Logger.setCurrentLogger"><a href="Logger.html#.setCurrentLogger">setCurrentLogger</a></li>
            
                <li data-name="Logger.setLevel"><a href="Logger.html#.setLevel">setLevel</a></li>
            
                <li data-name="Logger#debug"><a href="Logger.html#debug">debug</a></li>
            
                <li data-name="Logger#error"><a href="Logger.html#error">error</a></li>
            
                <li data-name="Logger#info"><a href="Logger.html#info">info</a></li>
            
                <li data-name="Logger#isDebug"><a href="Logger.html#isDebug">isDebug</a></li>
            
                <li data-name="Logger#isError"><a href="Logger.html#isError">isError</a></li>
            
                <li data-name="Logger#isInfo"><a href="Logger.html#isInfo">isInfo</a></li>
            
                <li data-name="Logger#isWarn"><a href="Logger.html#isWarn">isWarn</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Long">
            <span class="title">
                <a href="Long.html">Long</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="Long.MAX_VALUE"><a href="Long.html#.MAX_VALUE">MAX_VALUE</a></li>
            
                <li data-name="Long.MIN_VALUE"><a href="Long.html#.MIN_VALUE">MIN_VALUE</a></li>
            
                <li data-name="Long.NEG_ONE"><a href="Long.html#.NEG_ONE">NEG_ONE</a></li>
            
                <li data-name="Long.ONE"><a href="Long.html#.ONE">ONE</a></li>
            
                <li data-name="Long.ZERO"><a href="Long.html#.ZERO">ZERO</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Long.fromBits"><a href="Long.html#.fromBits">fromBits</a></li>
            
                <li data-name="Long.fromInt"><a href="Long.html#.fromInt">fromInt</a></li>
            
                <li data-name="Long.fromNumber"><a href="Long.html#.fromNumber">fromNumber</a></li>
            
                <li data-name="Long.fromString"><a href="Long.html#.fromString">fromString</a></li>
            
                <li data-name="Long#add"><a href="Long.html#add">add</a></li>
            
                <li data-name="Long#and"><a href="Long.html#and">and</a></li>
            
                <li data-name="Long#compare"><a href="Long.html#compare">compare</a></li>
            
                <li data-name="Long#div"><a href="Long.html#div">div</a></li>
            
                <li data-name="Long#equals"><a href="Long.html#equals">equals</a></li>
            
                <li data-name="Long#getHighBits"><a href="Long.html#getHighBits">getHighBits</a></li>
            
                <li data-name="Long#getLowBits"><a href="Long.html#getLowBits">getLowBits</a></li>
            
                <li data-name="Long#getLowBitsUnsigned"><a href="Long.html#getLowBitsUnsigned">getLowBitsUnsigned</a></li>
            
                <li data-name="Long#getNumBitsAbs"><a href="Long.html#getNumBitsAbs">getNumBitsAbs</a></li>
            
                <li data-name="Long#greaterThan"><a href="Long.html#greaterThan">greaterThan</a></li>
            
                <li data-name="Long#greaterThanOrEqual"><a href="Long.html#greaterThanOrEqual">greaterThanOrEqual</a></li>
            
                <li data-name="Long#isNegative"><a href="Long.html#isNegative">isNegative</a></li>
            
                <li data-name="Long#isOdd"><a href="Long.html#isOdd">isOdd</a></li>
            
                <li data-name="Long#isZero"><a href="Long.html#isZero">isZero</a></li>
            
                <li data-name="Long#lessThan"><a href="Long.html#lessThan">lessThan</a></li>
            
                <li data-name="Long#lessThanOrEqual"><a href="Long.html#lessThanOrEqual">lessThanOrEqual</a></li>
            
                <li data-name="Long#modulo"><a href="Long.html#modulo">modulo</a></li>
            
                <li data-name="Long#multiply"><a href="Long.html#multiply">multiply</a></li>
            
                <li data-name="Long#negate"><a href="Long.html#negate">negate</a></li>
            
                <li data-name="Long#not"><a href="Long.html#not">not</a></li>
            
                <li data-name="Long#notEquals"><a href="Long.html#notEquals">notEquals</a></li>
            
                <li data-name="Long#or"><a href="Long.html#or">or</a></li>
            
                <li data-name="Long#shiftLeft"><a href="Long.html#shiftLeft">shiftLeft</a></li>
            
                <li data-name="Long#shiftRight"><a href="Long.html#shiftRight">shiftRight</a></li>
            
                <li data-name="Long#shiftRightUnsigned"><a href="Long.html#shiftRightUnsigned">shiftRightUnsigned</a></li>
            
                <li data-name="Long#subtract"><a href="Long.html#subtract">subtract</a></li>
            
                <li data-name="Long#toInt"><a href="Long.html#toInt">toInt</a></li>
            
                <li data-name="Long#toJSON"><a href="Long.html#toJSON">toJSON</a></li>
            
                <li data-name="Long#toNumber"><a href="Long.html#toNumber">toNumber</a></li>
            
                <li data-name="Long#toString"><a href="Long.html#toString">toString</a></li>
            
                <li data-name="Long#xor"><a href="Long.html#xor">xor</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MaxKey">
            <span class="title">
                <a href="MaxKey.html">MaxKey</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MinKey">
            <span class="title">
                <a href="MinKey.html">MinKey</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MongoClient">
            <span class="title">
                <a href="MongoClient.html">MongoClient</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="MongoClient~connectCallback"><a href="MongoClient.html#~connectCallback">connectCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="MongoClient.connect"><a href="MongoClient.html#.connect">connect</a></li>
            
                <li data-name="MongoClient#connect"><a href="MongoClient.html#connect">connect</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MongoError">
            <span class="title">
                <a href="MongoError.html">MongoError</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="MongoError.create"><a href="MongoError.html#.create">create</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Mongos">
            <span class="title">
                <a href="Mongos.html">Mongos</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Mongos#connections"><a href="Mongos.html#connections">connections</a></li>
            
                <li data-name="Mongos#unref"><a href="Mongos.html#unref">unref</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="Mongos#event:close"><a href="Mongos.html#event:close">close</a></li>
            
                <li data-name="Mongos#event:connect"><a href="Mongos.html#event:connect">connect</a></li>
            
                <li data-name="Mongos#event:error"><a href="Mongos.html#event:error">error</a></li>
            
                <li data-name="Mongos#event:fullsetup"><a href="Mongos.html#event:fullsetup">fullsetup</a></li>
            
                <li data-name="Mongos#event:ha"><a href="Mongos.html#event:ha">ha</a></li>
            
                <li data-name="Mongos#event:joined"><a href="Mongos.html#event:joined">joined</a></li>
            
                <li data-name="Mongos#event:left"><a href="Mongos.html#event:left">left</a></li>
            
                <li data-name="Mongos#event:open"><a href="Mongos.html#event:open">open</a></li>
            
                <li data-name="Mongos#event:parseError"><a href="Mongos.html#event:parseError">parseError</a></li>
            
                <li data-name="Mongos#event:timeout"><a href="Mongos.html#event:timeout">timeout</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="ObjectID">
            <span class="title">
                <a href="ObjectID.html">ObjectID</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="ObjectID.createFromHexString"><a href="ObjectID.html#.createFromHexString">createFromHexString</a></li>
            
                <li data-name="ObjectID.createFromTime"><a href="ObjectID.html#.createFromTime">createFromTime</a></li>
            
                <li data-name="ObjectID.isValid"><a href="ObjectID.html#.isValid">isValid</a></li>
            
                <li data-name="ObjectID#equals"><a href="ObjectID.html#equals">equals</a></li>
            
                <li data-name="ObjectID#generate"><a href="ObjectID.html#generate">generate</a></li>
            
                <li data-name="ObjectID#getTimestamp"><a href="ObjectID.html#getTimestamp">getTimestamp</a></li>
            
                <li data-name="ObjectID#toHexString"><a href="ObjectID.html#toHexString">toHexString</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="OrderedBulkOperation">
            <span class="title">
                <a href="OrderedBulkOperation.html">OrderedBulkOperation</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="OrderedBulkOperation~resultCallback"><a href="OrderedBulkOperation.html#~resultCallback">resultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="OrderedBulkOperation#execute"><a href="OrderedBulkOperation.html#execute">execute</a></li>
            
                <li data-name="OrderedBulkOperation#find"><a href="OrderedBulkOperation.html#find">find</a></li>
            
                <li data-name="OrderedBulkOperation#insert"><a href="OrderedBulkOperation.html#insert">insert</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="ReadPreference">
            <span class="title">
                <a href="ReadPreference.html">ReadPreference</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="ReadPreference.isValid"><a href="ReadPreference.html#.isValid">isValid</a></li>
            
                <li data-name="ReadPreference#isValid"><a href="ReadPreference.html#isValid">isValid</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="ReplSet">
            <span class="title">
                <a href="ReplSet.html">ReplSet</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="ReplSet#connections"><a href="ReplSet.html#connections">connections</a></li>
            
                <li data-name="ReplSet#unref"><a href="ReplSet.html#unref">unref</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="ReplSet#event:close"><a href="ReplSet.html#event:close">close</a></li>
            
                <li data-name="ReplSet#event:connect"><a href="ReplSet.html#event:connect">connect</a></li>
            
                <li data-name="ReplSet#event:error"><a href="ReplSet.html#event:error">error</a></li>
            
                <li data-name="ReplSet#event:fullsetup"><a href="ReplSet.html#event:fullsetup">fullsetup</a></li>
            
                <li data-name="ReplSet#event:ha"><a href="ReplSet.html#event:ha">ha</a></li>
            
                <li data-name="ReplSet#event:joined"><a href="ReplSet.html#event:joined">joined</a></li>
            
                <li data-name="ReplSet#event:left"><a href="ReplSet.html#event:left">left</a></li>
            
                <li data-name="ReplSet#event:open"><a href="ReplSet.html#event:open">open</a></li>
            
                <li data-name="ReplSet#event:parseError"><a href="ReplSet.html#event:parseError">parseError</a></li>
            
                <li data-name="ReplSet#event:timeout"><a href="ReplSet.html#event:timeout">timeout</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Server">
            <span class="title">
                <a href="Server.html">Server</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Server#connections"><a href="Server.html#connections">connections</a></li>
            
                <li data-name="Server#unref"><a href="Server.html#unref">unref</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="Server#event:close"><a href="Server.html#event:close">close</a></li>
            
                <li data-name="Server#event:connect"><a href="Server.html#event:connect">connect</a></li>
            
                <li data-name="Server#event:error"><a href="Server.html#event:error">error</a></li>
            
                <li data-name="Server#event:parseError"><a href="Server.html#event:parseError">parseError</a></li>
            
                <li data-name="Server#event:reconnect"><a href="Server.html#event:reconnect">reconnect</a></li>
            
                <li data-name="Server#event:timeout"><a href="Server.html#event:timeout">timeout</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Symbol">
            <span class="title">
                <a href="Symbol.html">Symbol</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Symbol#valueOf"><a href="Symbol.html#valueOf">valueOf</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Timestamp">
            <span class="title">
                <a href="Timestamp.html">Timestamp</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Timestamp#toJSON"><a href="Timestamp.html#toJSON">toJSON</a></li>
            
                <li data-name="Timestamp.fromBits"><a href="Timestamp.html#.fromBits">fromBits</a></li>
            
                <li data-name="Timestamp.fromInt"><a href="Timestamp.html#.fromInt">fromInt</a></li>
            
                <li data-name="Timestamp.fromNumber"><a href="Timestamp.html#.fromNumber">fromNumber</a></li>
            
                <li data-name="Timestamp.fromString"><a href="Timestamp.html#.fromString">fromString</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="UnorderedBulkOperation">
            <span class="title">
                <a href="UnorderedBulkOperation.html">UnorderedBulkOperation</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="UnorderedBulkOperation~resultCallback"><a href="UnorderedBulkOperation.html#~resultCallback">resultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="UnorderedBulkOperation#execute"><a href="UnorderedBulkOperation.html#execute">execute</a></li>
            
                <li data-name="UnorderedBulkOperation#find"><a href="UnorderedBulkOperation.html#find">find</a></li>
            
                <li data-name="UnorderedBulkOperation#insert"><a href="UnorderedBulkOperation.html#insert">insert</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="WriteConcernError">
            <span class="title">
                <a href="WriteConcernError.html">WriteConcernError</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="WriteError">
            <span class="title">
                <a href="WriteError.html">WriteError</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
    </ul>
</div>
            </td>
            <td valign='top'>        
                <div class="main">
                    <h1 class="page-title" data-filename="Collection.html">Class: Collection</h1>
                    



<section>
    
<header>
    <h2>
    Collection
    </h2>
    
</header>  

<article>
    <div class="container-overview">
    
    
    
        
<dt>
    <div class="nameContainer">
        <h4 class="name" id="Collection">
            
            new Collection<span class="signature">()</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{<a href="Collection.html">Collection</a>}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line61">line 61</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Create a new Collection instance (INTERNAL TYPE, do not instantiate directly)</p>
    </div>
    

    
    
    
    
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>collectionName</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Get the collection name.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>namespace</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Get the full collection namespace.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>writeConcern</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The current write concern values.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>readConcern</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The current read concern values.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>hint</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Get current index hint for collection.</p></td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Collection instance.
<br />

    
    
    
</dd>

    
    </div>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        <h3 class="subsection-title">Methods</h3>
        
        <dl>
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="aggregate">
            
            aggregate<span class="signature">(pipeline, <span class="optional">options</span>, callback)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{null|<a href="AggregationCursor.html">AggregationCursor</a>}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2586">line 2586</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Execute an aggregation framework pipeline against the collection, needs MongoDB &gt;= 2.2</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>pipeline</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Array containing all the aggregation framework commands for the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>readPreference</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="ReadPreference.html">ReadPreference</a></span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>cursor</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Return the query as cursor, on 2.6 &gt; it returns as a real cursor on pre 2.6 it returns as an emulated cursor.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>batchSize</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The batchSize for the cursor</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>explain</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Explain returns the aggregation execution plan (requires mongodb 2.6 &gt;).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>allowDiskUse</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>allowDiskUse lets the server know if it can use disk to store temporary results for the aggregation (requires mongodb 2.6 &gt;).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>maxTimeMS</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>maxTimeMS specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>bypassDocumentValidation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allow driver to bypass schema validation in MongoDB 3.2 or higher.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>raw</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Return document results as raw BSON buffers.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>promoteLongs</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    true
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Promotes Long values to number if they fit inside the 53 bits resolution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>promoteValues</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    true
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Promotes BSON values to native types where possible, set to false to only receive wrapper types.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>promoteBuffers</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Promotes Binary BSON values to native Node Buffers.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>collation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Correctly call the aggregation framework using a pipeline in an Array.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Some docs for insertion
  var docs = [{
      title : "this is my title", author : "bob", posted : new Date() ,
      pageViews : 5, tags : [ "fun" , "good" , "fun" ], other : { foo : 5 },
      comments : [
        { author :"joe", text : "this is cool" }, { author :"sam", text : "this is bad" }
      ]}];

  // Create a collection
  var collection = db.collection('aggregationExample1');
  // Insert the docs
  collection.insertMany(docs, {w: 1}, function(err, result) {

    // Execute aggregate, notice the pipeline is expressed as an Array
    collection.aggregate([
        { $project : {
          author : 1,
          tags : 1
        }},
        { $unwind : "$tags" },
        { $group : {
          _id : {tags : "$tags"},
          authors : { $addToSet : "$author" }
        }}
      ], function(err, result) {
        test.equal(null, err);
        test.equal('good', result[0]._id.tags);
        test.deepEqual(['bob'], result[0].authors);
        test.equal('fun', result[1]._id.tags);
        test.deepEqual(['bob'], result[1].authors);

        db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Correctly call the aggregation using a cursor

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Some docs for insertion
  var docs = [{
      title : "this is my title", author : "bob", posted : new Date() ,
      pageViews : 5, tags : [ "fun" , "good" , "fun" ], other : { foo : 5 },
      comments : [
        { author :"joe", text : "this is cool" }, { author :"sam", text : "this is bad" }
      ]}];

  // Create a collection
  var collection = db.collection('aggregationExample2');
  // Insert the docs
  collection.insertMany(docs, {w: 1}, function(err, result) {

    // Execute aggregate, notice the pipeline is expressed as an Array
    var cursor = collection.aggregate([
        { $project : {
          author : 1,
          tags : 1
        }},
        { $unwind : "$tags" },
        { $group : {
          _id : {tags : "$tags"},
          authors : { $addToSet : "$author" }
        }}
      ], { cursor: { batchSize: 1 } });

    // Get all the aggregation results
    cursor.toArray(function(err, docs) {
      test.equal(null, err);
      test.equal(2, docs.length);
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Correctly call the aggregation using a read stream

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Some docs for insertion
  var docs = [{
      title : "this is my title", author : "bob", posted : new Date() ,
      pageViews : 5, tags : [ "fun" , "good" , "fun" ], other : { foo : 5 },
      comments : [
        { author :"joe", text : "this is cool" }, { author :"sam", text : "this is bad" }
      ]}];

  // Create a collection
  var collection = db.collection('aggregationExample3');
  // Insert the docs
  collection.insertMany(docs, {w: 1}, function(err, result) {

    // Execute aggregate, notice the pipeline is expressed as an Array
    var cursor = collection.aggregate([
        { $project : {
          author : 1,
          tags : 1
        }},
        { $unwind : "$tags" },
        { $group : {
          _id : {tags : "$tags"},
          authors : { $addToSet : "$author" }
        }}
      ], { cursor: { batchSize: 1 } });

    var count = 0;
    // Get all the aggregation results
    cursor.on('data', function(doc) {
      count = count + 1;
    });

    cursor.once('end', function() {
      test.equal(2, count);
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Call toArray on an aggregation cursor using a Promise

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Some docs for insertion
  var docs = [{
      title : "this is my title", author : "bob", posted : new Date() ,
      pageViews : 5, tags : [ "fun" , "good" , "fun" ], other : { foo : 5 },
      comments : [
        { author :"joe", text : "this is cool" }, { author :"sam", text : "this is bad" }
      ]}];

  // Create a collection
  var collection = db.collection('aggregationExample2_with_promise');
  // Insert the docs
  collection.insertMany(docs, {w: 1}).then(function(result) {
    // Execute aggregate, notice the pipeline is expressed as an Array
    var cursor = collection.aggregate([
        { $project : {
          author : 1,
          tags : 1
        }},
        { $unwind : "$tags" },
        { $group : {
          _id : {tags : "$tags"},
          authors : { $addToSet : "$author" }
        }}
      ], { cursor: { batchSize: 1 } });
    // Get all the aggregation results
    cursor.toArray().then(function(docs) {
      test.equal(2, docs.length);
      db.close();
    }).catch(function(err) {
      console.log(err.stack);
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Call toArray on an aggregation cursor using ES6 generators and the co module

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Some docs for insertion
  var docs = [{
      title : "this is my title", author : "bob", posted : new Date() ,
      pageViews : 5, tags : [ "fun" , "good" , "fun" ], other : { foo : 5 },
      comments : [
        { author :"joe", text : "this is cool" }, { author :"sam", text : "this is bad" }
      ]}];

  // Create a collection
  var collection = db.collection('aggregationExample2_with_generatorsGenerator');

  // Insert the docs
  yield collection.insertMany(docs, {w: 1});

  // Execute aggregate, notice the pipeline is expressed as an Array
  var cursor = collection.aggregate([
      { $project : {
        author : 1,
        tags : 1
      }},
      { $unwind : "$tags" },
      { $group : {
        _id : {tags : "$tags"},
        authors : { $addToSet : "$author" }
      }}
    ], { cursor: { batchSize: 1 } });

  // Get all the aggregation results
  var docs = yield cursor.toArray();
  test.equal(2, docs.length);
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="bulkWrite">
            
            bulkWrite<span class="signature">(operations, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line601">line 601</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Perform a bulkWrite operation without a fluent API</p>
<p>Legal operation types are</p>
<p> { insertOne: { document: { a: 1 } } }</p>
<p> { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }</p>
<p> { updateMany: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }</p>
<p> { deleteOne: { filter: {c:1} } }</p>
<p> { deleteMany: { filter: {c:1} } }</p>
<p> { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true}}</p>
<p>If documents passed in do not contain the <strong>_id</strong> field,<br>one will be added to each of the documents missing it by the driver, mutating the document. This behavior<br>can be overridden by setting the <strong>forceServerObjectId</strong> flag.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>operations</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Array.&lt;object></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Bulk operations to perform.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>serializeFunctions</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Serialize functions on any object.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>ordered</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    true
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Execute write operation in ordered or unordered fashion.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>bypassDocumentValidation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allow driver to bypass schema validation in MongoDB 3.2 or higher.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~bulkWriteOpCallback">Collection~bulkWriteOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple bulkWrite operation

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('bulk_write');
  col.bulkWrite([
      { insertOne: { document: { a: 1 } } }
    , { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
    , { updateMany: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
    , { deleteOne: { filter: {c:1} } }
    , { deleteMany: { filter: {c:1} } }
    , { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true}}]
  , {ordered:true, w:1}, function(err, r) {
    test.equal(null, err);
    test.equal(1, r.nInserted);
    test.equal(2, r.nUpserted);
    test.equal(0, r.nRemoved);

    // Crud fields
    test.equal(1, r.insertedCount);
    test.equal(1, Object.keys(r.insertedIds).length);
    test.equal(1, r.matchedCount);
    test.ok(r.modifiedCount == 0 || r.modifiedCount == 1);
    test.equal(0, r.deletedCount);
    test.equal(2, r.upsertedCount);
    test.equal(2, Object.keys(r.upsertedIds).length);

    // Ordered bulk operation
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple bulkWrite operation using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('bulk_write_with_promise');
  col.bulkWrite([
      { insertOne: { document: { a: 1 } } }
    , { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
    , { updateMany: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
    , { deleteOne: { filter: {c:1} } }
    , { deleteMany: { filter: {c:1} } }
    , { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true}}]
  , {ordered:true, w:1}).then(function(r) {
    // console.log(JSON.stringify(r, null, 2))
    test.equal(1, r.nInserted);
    test.equal(2, r.nUpserted);
    test.equal(0, r.nRemoved);
    // Crud fields
    test.equal(1, r.insertedCount);
    test.equal(1, Object.keys(r.insertedIds).length);
    test.equal(1, r.matchedCount);
    test.ok(r.modifiedCount == 0 || r.modifiedCount == 1);
    test.equal(0, r.deletedCount);
    test.equal(2, r.upsertedCount);
    test.equal(2, Object.keys(r.upsertedIds).length);

    // Ordered bulk operation
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple bulkWrite operation using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Get the collection
  var col = db.collection('bulk_write_with_generators');
  var r = yield col.bulkWrite([
      { insertOne: { document: { a: 1 } } }
    , { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
    , { updateMany: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
    , { deleteOne: { filter: {c:1} } }
    , { deleteMany: { filter: {c:1} } }
    , { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true}}]
  , {ordered:true, w:1});
  test.equal(1, r.nInserted);
  test.equal(2, r.nUpserted);
  test.equal(0, r.nRemoved);

  // Crud fields
  test.equal(1, r.insertedCount);
  test.equal(1, Object.keys(r.insertedIds).length);
  test.equal(1, r.matchedCount);
  test.ok(r.modifiedCount == 0 || r.modifiedCount == 1);
  test.equal(0, r.deletedCount);
  test.equal(2, r.upsertedCount);
  test.equal(2, Object.keys(r.upsertedIds).length);

  // Ordered bulk operation
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="count">
            
            count<span class="signature">(query, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2003">line 2003</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Count number of matching documents in the db to a query.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>query</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The query for the count.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>limit</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The limit of documents to count.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>skip</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The number of documents to skip for the count.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>hint</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>An index name hint for the query.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>readPreference</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="ReadPreference.html">ReadPreference</a></span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>maxTimeMS</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Number of milliseconds to wait before aborting the query.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~countCallback">Collection~countCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of running simple count commands against a collection.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Crete the collection for the distinct example
  var collection = db.collection('countExample1');
  // Insert documents to perform distinct against
  collection.insertMany([{a:1}, {a:2}
    , {a:3}, {a:4, b:1}], {w: 1}, function(err, ids) {

    // Perform a total count command
    collection.count(function(err, count) {
      test.equal(null, err);
      test.equal(4, count);

      // Perform a partial account where b=1
      collection.count({b:1}, function(err, count) {
        test.equal(null, err);
        test.equal(1, count);

        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of running simple count commands against a collection using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Crete the collection for the distinct example
  var collection = db.collection('countExample1_with_promise');
  // Insert documents to perform distinct against
  collection.insertMany([{a:1}, {a:2}
    , {a:3}, {a:4, b:1}], {w: 1}).then(function(ids) {
    // Perform a total count command
    collection.count().then(function(count) {
      test.equal(4, count);

      // Perform a partial account where b=1
      collection.count({b:1}).then(function(count) {
        test.equal(1, count);

        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of running simple count commands against a collection using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Crete the collection for the distinct example
  var collection = db.collection('countExample1_with_generators');
  // Insert documents to perform distinct against
  var result = yield collection.insertMany([{a:1}, {a:2}
    , {a:3}, {a:4, b:1}], {w: 1});
  // Perform a total count command
  var count = yield collection.count();
  test.equal(4, count);

  // Perform a partial account where b=1
  var count = yield collection.count({b:1});
  test.equal(1, count);

  // Close database
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="createIndex">
            
            createIndex<span class="signature">(fieldOrSpec, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1597">line 1597</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Creates an index on the db and collection collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>fieldOrSpec</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>
|

<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Defines the index.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>unique</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Creates an unique index.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>sparse</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Creates a sparse index.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>background</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Creates the index in the background, yielding whenever possible.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>dropDups</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>A unique index cannot be created on a key that has pre-existing duplicate values. If you would like to create the index anyway, keeping the first document the database indexes and deleting all subsequent documents that have duplicate value</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>min</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>For geospatial indexes set the lower bound for the co-ordinates.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>max</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>For geospatial indexes set the high bound for the co-ordinates.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>v</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify the format version of the indexes.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>expireAfterSeconds</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher)</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>name</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Override the autogenerated index name (useful if the resulting name is larger than 128 bytes)</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>partialFilterExpression</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Creates a partial index based on the given filter object (MongoDB 3.2 or higher)</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>collation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// A more complex createIndex using a compound unique index in the background and dropping duplicated documents

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Create a collection we want to drop later
  var collection = db.collection('createIndexExample1');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Create an index on the a field
    collection.createIndex({a:1, b:1}
      , {unique:true, background:true, w:1}, function(err, indexName) {

      // Show that duplicate records got dropped
      collection.find({}).toArray(function(err, items) {
        test.equal(null, err);
        test.equal(4, items.length);

        // Perform a query, with explain to show we hit the query
        collection.find({a:2}).explain(function(err, explanation) {
          test.equal(null, err);
          test.ok(explanation != null);

          db.close();
        });
      })
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple createIndex using a simple single field index

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('createIndexExample2');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1}, {a:2}, {a:3}, {a:4}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Create an index on the a field
    collection.createIndex('a', {w:1}, function(err, indexName) {
      test.equal("a_1", indexName);

      // Perform a query, with explain to show we hit the query
      collection.find({a:2}).explain(function(err, explanation) {
        test.equal(null, err);
        test.ok(explanation != null);

        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A more complex createIndex using a compound unique index in the background

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('createIndexExample3');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) {
    test.equal(null, err);

    var options = {unique:true, background:true, w:1};
    // Create an index on the a field
    collection.createIndex({a:1, b:1}
      , options, function(err, indexName) {

      test.ok(!options.readPreference);
      // Show that duplicate records got dropped
      collection.find({}).toArray(function(err, items) {
        test.equal(null, err);
        test.equal(4, items.length);

        // Perform a query, with explain to show we hit the query
        collection.find({a:2}).explain(function(err, explanation) {
          test.equal(null, err);
          test.ok(explanation != null);

          db.close();
        });
      })
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A more complex createIndex using a Promise and a compound unique index in the background and dropping duplicated documents

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Create a collection we want to drop later
  var collection = db.collection('createIndexExample1_with_promise');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}).then(function(result) {

    // Create an index on the a field
    collection.createIndex({a:1, b:1}
      , {unique:true, background:true, w:1}).then(function(indexName) {

      // Show that duplicate records got dropped
      collection.find({}).toArray().then(function(items) {
        test.equal(4, items.length);

        // Perform a query, with explain to show we hit the query
        collection.find({a:2}).explain().then(function(explanation) {
          test.ok(explanation != null);

          db.close();
        });
      })
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A more complex createIndex using a Generator and the co module and a compound unique index in the background and dropping duplicated documents

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Create a collection we want to drop later
  var collection = db.collection('createIndexExample1_with_generators');
  // Insert a bunch of documents for the index
  yield collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1});

  // Create an index on the a field
  yield collection.createIndex({a:1, b:1}
    , {unique:true, background:true, w:1});

  // Show that duplicate records got dropped
  var items = yield collection.find({}).toArray();
  test.equal(4, items.length);

  // Perform a query, with explain to show we hit the query
  var explanation = yield collection.find({a:2}).explain()
  test.ok(explanation != null);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="createIndexes">
            
            createIndexes<span class="signature">(indexSpecs, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1633">line 1633</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Creates multiple indexes in the collection, this method is only supported for<br>MongoDB 2.6 or higher. Earlier version of MongoDB will throw a command not supported<br>error. Index specifications are defined at https://www.mongodb.com/docs/manual/reference/command/createIndexes/.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>indexSpecs</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">array</span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>An array of index specifications to be created</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="deleteMany">
            
            deleteMany<span class="signature">(filter, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1184">line 1184</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Delete multiple documents on MongoDB</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>filter</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The Filter used to select the documents to remove</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~deleteWriteOpCallback">Collection~deleteWriteOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="deleteOne">
            
            deleteOne<span class="signature">(filter, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1133">line 1133</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Delete a document on MongoDB</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>filter</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The Filter used to select the document to remove</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~deleteWriteOpCallback">Collection~deleteWriteOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="distinct">
            
            distinct<span class="signature">(key, query, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2076">line 2076</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The distinct command returns returns a list of distinct values for the given key across a collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>key</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Field of the document to find distinct values for.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>query</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The query for filtering the set of documents to which we apply the distinct filter.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>readPreference</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="ReadPreference.html">ReadPreference</a></span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>maxTimeMS</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Number of milliseconds to wait before aborting the query.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of running the distinct command against a collection

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Crete the collection for the distinct example
  var collection = db.collection('distinctExample1');

  // Insert documents to perform distinct against
  collection.insertMany([{a:0, b:{c:'a'}}, {a:1, b:{c:'b'}}, {a:1, b:{c:'c'}},
    {a:2, b:{c:'a'}}, {a:3}, {a:3}], {w:1}, function(err, ids) {

    // Perform a distinct query against the a field
    collection.distinct('a', function(err, docs) {
      test.deepEqual([0, 1, 2, 3], docs.sort());

      // Perform a distinct query against the sub-field b.c
      collection.distinct('b.c', function(err, docs) {
        test.deepEqual(['a', 'b', 'c'], docs.sort());

        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of running the distinct command against a collection with a filter query

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Crete the collection for the distinct example
  var collection = db.collection('distinctExample2');

  // Insert documents to perform distinct against
  collection.insertMany([{a:0, b:{c:'a'}}, {a:1, b:{c:'b'}}, {a:1, b:{c:'c'}},
    {a:2, b:{c:'a'}}, {a:3}, {a:3}, {a:5, c:1}], {w:1}, function(err, ids) {

    // Perform a distinct query with a filter against the documents
    collection.distinct('a', {c:1}, function(err, docs) {
      test.deepEqual([5], docs.sort());

      db.close();
    });
  })
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of running the distinct command using a Promise against a collection

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Crete the collection for the distinct example
  var collection = db.collection('distinctExample1_with_promise');

  // Insert documents to perform distinct against
  collection.insertMany([{a:0, b:{c:'a'}}, {a:1, b:{c:'b'}}, {a:1, b:{c:'c'}},
    {a:2, b:{c:'a'}}, {a:3}, {a:3}], {w:1}).then(function(ids) {

    // Perform a distinct query against the a field
    collection.distinct('a').then(function(docs) {
      test.deepEqual([0, 1, 2, 3], docs.sort());

      // Perform a distinct query against the sub-field b.c
      collection.distinct('b.c').then(function(docs) {
        test.deepEqual(['a', 'b', 'c'], docs.sort());

        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of running the distinct command using a Generator and the co module against a collection

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Crete the collection for the distinct example
  var collection = db.collection('distinctExample1_with_generators');

  // Insert documents to perform distinct against
  yield collection.insertMany([{a:0, b:{c:'a'}}, {a:1, b:{c:'b'}}, {a:1, b:{c:'c'}},
    {a:2, b:{c:'a'}}, {a:3}, {a:3}], {w:1});

  // Perform a distinct query against the a field
  var docs = yield collection.distinct('a');
  test.deepEqual([0, 1, 2, 3], docs.sort());

  // Perform a distinct query against the sub-field b.c
  var docs = yield collection.distinct('b.c');
  test.deepEqual(['a', 'b', 'c'], docs.sort());

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="drop">
            
            drop<span class="signature">(<span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1491">line 1491</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Drop the collection from the database, removing it permanently. New accesses will create a new collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The results callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple collection drop.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('test_other_drop');

  // Drop the collection
  collection.drop(function(err, reply) {

    // Ensure we don't have the collection in the set of names
    db.listCollections().toArray(function(err, replies) {

      var found = false;
      // For each collection in the list of collection names in this db look for the
      // dropped collection
      replies.forEach(function(document) {
        if(document.name == "test_other_drop") {
          found = true;
          return;
        }
      });

      // Ensure the collection is not found
      test.equal(false, found);

      // Let's close the db
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of Collection.prototype.drop using a Promise

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  db.createCollection('test_other_drop_with_promise').then(function(collection) {
    // Drop the collection
    collection.drop().then(function(reply) {

      // Ensure we don't have the collection in the set of names
      db.listCollections().toArray().then(function(replies) {

        var found = false;
        // For each collection in the list of collection names in this db look for the
        // dropped collection
        replies.forEach(function(document) {
          if(document.name == "test_other_drop_with_promise") {
            found = true;
            return;
          }
        });

        // Ensure the collection is not found
        test.equal(false, found);

        // Let's close the db
        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of Collection.prototype.drop using a Generator and the co module

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection we want to drop later
  var collection = yield db.createCollection('test_other_drop_with_generators');

  // Drop the collection
  yield collection.drop();

  // Ensure we don't have the collection in the set of names
  var replies = yield db.listCollections().toArray();

  // Did we find the collection
  var found = false;
  // For each collection in the list of collection names in this db look for the
  // dropped collection
  replies.forEach(function(document) {
    if(document.name == "test_other_drop_with_generators") {
      found = true;
      return;
    }
  });

  // Ensure the collection is not found
  test.equal(false, found);

  // Let's close the db
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="dropAllIndexes">
            
            dropAllIndexes<span class="signature">(callback)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1768">line 1768</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Drops all indexes from this collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
        <dt class="important tag-deprecated">Deprecated</dt><dd><ul class="dummy"><li>use dropIndexes</li><ul></dd>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no [callback] passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a how to drop all the indexes on a collection using dropAllIndexes

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  db.createCollection('dropExample1', function(err, r) {
    test.equal(null, err);

    // Drop the collection
    db.collection('dropExample1').dropAllIndexes(function(err, reply) {
      test.equal(null, err);

      // Let's close the db
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a how to drop all the indexes on a collection using dropAllIndexes with a Promise

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  db.createCollection('dropExample1_with_promise').then(function(r) {
    // Drop the collection
    db.collection('dropExample1_with_promise').dropAllIndexes().then(function(reply) {
      // Let's close the db
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a how to drop all the indexes on a collection using dropAllIndexes with a Generator and the co module

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  yield db.createCollection('dropExample1_with_generators');
  // Drop the collection
  yield db.collection('dropExample1_with_generators').dropAllIndexes();
  // Let's close the db
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="dropIndex">
            
            dropIndex<span class="signature">(indexName, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1689">line 1689</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Drops an index from this collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>indexName</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Name of the index to drop.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// An examples showing the creation and dropping of an index

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var collection = db.collection('dropIndexExample1');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}, function(err, indexName) {

      // Drop the index
      collection.dropIndex("a_1_b_1", function(err, result) {
        test.equal(null, err);

        // Verify that the index is gone
        collection.indexInformation(function(err, indexInformation) {
          test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
          test.equal(null, indexInformation.a_1_b_1);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An examples showing the creation and dropping of an index using a Promise

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var collection = db.collection('dropIndexExample1_with_promise');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}).then(function(result) {

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}).then(function(indexName) {

      // Drop the index
      collection.dropIndex("a_1_b_1").then(function(result) {

        // Verify that the index is gone
        collection.indexInformation().then(function(indexInformation) {
          test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
          test.equal(null, indexInformation.a_1_b_1);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An examples showing the creation and dropping of an index using a Generator and the co module

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  var collection = db.collection('dropIndexExample1_with_generators');
  // Insert a bunch of documents for the index
  yield collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1});

  // Create an index on the a field
  yield collection.ensureIndex({a:1, b:1}
    , {unique:true, background:true, w:1});

  // Drop the index
  yield collection.dropIndex("a_1_b_1");

  // Verify that the index is gone
  var indexInformation = yield collection.indexInformation()
  test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
  test.equal(null, indexInformation.a_1_b_1);

  // Close db
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="dropIndexes">
            
            dropIndexes<span class="signature">(<span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1733">line 1733</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Drops all indexes from this collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// An examples showing the creation and dropping of an index

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('shouldCorrectlyCreateAndDropAllIndex');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}, function(err, indexName) {

      // Create an additional index
      collection.ensureIndex({c:1}
        , {unique:true, background:true, w:1}, function(err, indexName) {

        // Drop the index
        collection.dropAllIndexes(function(err, result) {
          test.equal(null, err);

          // Verify that the index is gone
          collection.indexInformation(function(err, indexInformation) {
            test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
            test.equal(null, indexInformation.a_1_b_1);
            test.equal(null, indexInformation.c_1);

            db.close();
          });
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An examples showing the creation and dropping of an index using Promises.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('shouldCorrectlyCreateAndDropAllIndex_with_promise');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {w:1}).then(function(result) {

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}).then(function(indexName) {

      // Create an additional index
      collection.ensureIndex({c:1}
        , {unique:true, background:true, sparse:true, w:1}).then(function(indexName) {

        // Drop the index
        collection.dropAllIndexes().then(function(result) {

          // Verify that the index is gone
          collection.indexInformation().then(function(indexInformation) {
            test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
            test.equal(null, indexInformation.a_1_b_1);
            test.equal(null, indexInformation.c_1);

            db.close();
          });
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An examples showing the creation and dropping of an index using Generators.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection we want to drop later
  var collection = db.collection('shouldCorrectlyCreateAndDropAllIndex_with_generators');
  // Insert a bunch of documents for the index
  yield collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {w:1});

  // Create an index on the a field
  yield collection.ensureIndex({a:1, b:1}
    , {unique:true, background:true, w:1});

  // Create an additional index
  yield collection.ensureIndex({c:1}
    , {unique:true, background:true, sparse:true, w:1});

  // Drop the index
  yield collection.dropAllIndexes();

  // Verify that the index is gone
  var indexInformation = yield collection.indexInformation();
  test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
  test.equal(null, indexInformation.a_1_b_1);
  test.equal(null, indexInformation.c_1);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="ensureIndex">
            
            ensureIndex<span class="signature">(fieldOrSpec, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1884">line 1884</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Ensures that an index exists, if it does not it creates it</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>fieldOrSpec</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>
|

<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Defines the index.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>unique</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Creates an unique index.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>sparse</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Creates a sparse index.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>background</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Creates the index in the background, yielding whenever possible.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>dropDups</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>A unique index cannot be created on a key that has pre-existing duplicate values. If you would like to create the index anyway, keeping the first document the database indexes and deleting all subsequent documents that have duplicate value</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>min</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>For geospatial indexes set the lower bound for the co-ordinates.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>max</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>For geospatial indexes set the high bound for the co-ordinates.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>v</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify the format version of the indexes.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>expireAfterSeconds</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher)</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>name</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Override the autogenerated index name (useful if the resulting name is larger than 128 bytes)</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>collation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
        <dt class="important tag-deprecated">Deprecated</dt><dd><ul class="dummy"><li>use createIndexes instead</li><ul></dd>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// A more complex ensureIndex using a compound unique index in the background and dropping duplicated documents.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var collection = db.collection('ensureIndexExample1');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Create an index on the a field
    db.ensureIndex('ensureIndexExample1', {a:1, b:1}
      , {unique:true, background:true, w:1}, function(err, indexName) {

      // Show that duplicate records got dropped
      collection.find({}).toArray(function(err, items) {
        test.equal(null, err);
        test.equal(4, items.length);

        // Perform a query, with explain to show we hit the query
        collection.find({a:2}).explain(function(err, explanation) {
          test.equal(null, err);
          test.ok(explanation != null);

          db.close();
        });
      })
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A more complex ensureIndex using a compound unique index in the background.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var collection = db.collection('ensureIndexExample2');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}, function(err, indexName) {
      test.equal(null, err);

      // Show that duplicate records got dropped
      collection.find({}).toArray(function(err, items) {
        test.equal(null, err);
        test.equal(4, items.length);

        // Perform a query, with explain to show we hit the query
        collection.find({a:2}).explain(function(err, explanation) {
          test.equal(null, err);
          test.ok(explanation != null);

          db.close();
        });
      })
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A more complex ensureIndex using a compound unique index in the background and dropping duplicated documents using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var collection = db.collection('ensureIndexExample1_with_promise');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}).then(function(result) {

    // Create an index on the a field
    db.ensureIndex('ensureIndexExample1_with_promise', {a:1, b:1}
      , {unique:true, background:true, w:1}).then(function(indexName) {

      // Show that duplicate records got dropped
      collection.find({}).toArray().then(function(items) {
        test.equal(4, items.length);

        // Perform a query, with explain to show we hit the query
        collection.find({a:2}).explain().then(function(explanation) {
          test.ok(explanation != null);

          db.close();
        });
      })
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A more complex ensureIndex using a compound unique index in the background using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var collection = db.collection('ensureIndexExample2_with_promise');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}).then(function(result) {

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}).then(function(indexName) {

      // Show that duplicate records got dropped
      collection.find({}).toArray().then(function(items) {
        test.equal(4, items.length);

        // Perform a query, with explain to show we hit the query
        collection.find({a:2}).explain().then(function(explanation) {
          test.ok(explanation != null);

          db.close();
        });
      })
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A more complex ensureIndex using a compound unique index in the background and dropping duplicated documents using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  var collection = db.collection('ensureIndexExample1_with_generators');
  // Insert a bunch of documents for the index
  yield collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1});

  // Create an index on the a field
  yield db.ensureIndex('ensureIndexExample1_with_generators', {a:1, b:1}
    , {unique:true, background:true, w:1});

  // Show that duplicate records got dropped
  var items = yield collection.find({}).toArray();
  test.equal(4, items.length);

  // Perform a query, with explain to show we hit the query
  var explanation = yield collection.find({a:2}).explain();
  test.ok(explanation != null);

  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A more complex ensureIndex using a compound unique index in the background using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  var collection = db.collection('ensureIndexExample2_with_generators');
  // Insert a bunch of documents for the index
  yield collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1});

  // Create an index on the a field
  yield collection.ensureIndex({a:1, b:1}
    , {unique:true, background:true, w:1});

  // Show that duplicate records got dropped
  var items = yield collection.find({}).toArray();
  test.equal(4, items.length);

  // Perform a query, with explain to show we hit the query
  var explanation = yield collection.find({a:2}).explain();
  test.ok(explanation != null);

  // Close db
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="find">
            
            find<span class="signature">(query)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{<a href="Cursor.html">Cursor</a>}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line180">line 180</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Creates a cursor for a query that can be used to iterate over results from MongoDB</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>query</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The cursor query object.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    <h5>Throws:</h5>
    
            

    <div class="param-desc">
    
        
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


    
    </div>


        
    
    
    
    


    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// A simple query using the find method on the collection.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('simple_query');

  // Insert a bunch of documents for the testing
  collection.insertMany([{a:1}, {a:2}, {a:3}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Perform a simple find and return all the documents
    collection.find().toArray(function(err, docs) {
      test.equal(null, err);
      test.equal(3, docs.length);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple query showing the explain for a query

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('simple_explain_query');
  // Insert a bunch of documents for the testing
  collection.insertMany([{a:1}, {a:2}, {a:3}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Perform a simple find and return all the documents
    collection.find({}).explain(function(err, explain) {
      test.equal(null, err);
      test.ok(explain != null);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple query showing skip and limit

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('simple_limit_skip_query');
  // Insert a bunch of documents for the testing
  collection.insertMany([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Perform a simple find and return all the documents
    collection.find({})
      .skip(1).limit(1).project({b:1}).toArray(function(err, docs) {
        test.equal(null, err);
        test.equal(1, docs.length);
        test.equal(null, docs[0].a);
        test.equal(2, docs[0].b);

        db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple query using the find method and toArray method with a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('simple_query_with_promise');

  // Insert a bunch of documents for the testing
  collection.insertMany([{a:1}, {a:2}, {a:3}], {w:1}).then(function(result) {

    // Perform a simple find and return all the documents
    collection.find().toArray().then(function(docs) {
      test.equal(3, docs.length);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple query showing the explain for a query using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('simple_explain_query_with_promise');
  // Insert a bunch of documents for the testing
  collection.insertMany([{a:1}, {a:2}, {a:3}], {w:1}).then(function(result) {

    // Perform a simple find and return all the documents
    collection.find({}).explain().then(function(docs) {
      test.ok(docs != null);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple query showing skip and limit using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('simple_limit_skip_query_with_promise');
  // Insert a bunch of documents for the testing
  collection.insertMany([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}).then(function(result) {

    // Perform a simple find and return all the documents
    collection.find({})
      .skip(1).limit(1).project({b:1}).toArray().then(function(docs) {
        test.equal(1, docs.length);
        test.equal(null, docs[0].a);
        test.equal(2, docs[0].b);

        db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple query using the find method and toArray method with a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection we want to drop later
  var collection = db.collection('simple_query_with_generators');

  // Insert a bunch of documents for the testing
  yield collection.insertMany([{a:1}, {a:2}, {a:3}], {w:1});

  // Perform a simple find and return all the documents
  var docs = yield collection.find().toArray();
  test.equal(3, docs.length);

  // Close the db
  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple query showing the explain for a query using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection we want to drop later
  var collection = db.collection('simple_explain_query_with_generators');
  // Insert a bunch of documents for the testing
  yield collection.insertMany([{a:1}, {a:2}, {a:3}], {w:1});

  // Perform a simple find and return all the documents
  var explain = yield collection.find({}).explain();
  test.ok(explain != null);

  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple query showing skip and limit using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection we want to drop later
  var collection = db.collection('simple_limit_skip_query_with_generators');
  // Insert a bunch of documents for the testing
  yield collection.insertMany([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1});

  // Perform a simple find and return all the documents
  var docs = yield collection.find({})
  .skip(1).limit(1).project({b:1}).toArray();
    test.equal(1, docs.length);
    test.equal(null, docs[0].a);
    test.equal(2, docs[0].b);

    // Close db
    db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="findAndModify">
            
            findAndModify<span class="signature">(query, sort, doc, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2407">line 2407</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Find and update a document.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>query</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Query object to locate the object to modify.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>sort</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">array</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>If multiple docs match, choose the first one in the specified sort order as the object to manipulate.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>doc</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The fields/vals to be updated.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>remove</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Set to true to remove the object before returning.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>upsert</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Perform an upsert operation.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>new</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Set to true if you want to return the modified object rather than the original. Ignored for remove.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>fields</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Object containing the field projection for the result returned from the operation.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~findAndModifyCallback">Collection~findAndModifyCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
        <dt class="important tag-deprecated">Deprecated</dt><dd><ul class="dummy"><li>use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead</li><ul></dd>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// A whole set of different ways to use the findAndModify command.
// The first findAndModify command modifies a document and returns the modified document back.<br>The second findAndModify command removes the document.<br>The second findAndModify command upserts a document and returns the new document.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Create a collection we want to drop later
  var collection = db.collection('simple_find_and_modify_operations_');

  // Insert some test documentations
  collection.insertMany([{a:1}, {b:1}, {c:1}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Simple findAndModify command returning the new document
    collection.findAndModify({a:1}, [['a', 1]], {$set:{b1:1}}, {new:true}, function(err, doc) {
      test.equal(null, err);
      test.equal(1, doc.value.a);
      test.equal(1, doc.value.b1);

      // Simple findAndModify command returning the new document and
      // removing it at the same time
      collection.findAndModify({b:1}, [['b', 1]],
        {$set:{b:2}}, {remove:true}, function(err, doc) {

        // Verify that the document is gone
        collection.findOne({b:1}, function(err, item) {
          test.equal(null, err);
          test.equal(null, item);

          // Simple findAndModify command performing an upsert and returning the new document
          // executing the command safely
          collection.findAndModify({d:1}, [['b', 1]],
            {d:1, f:1}, {new:true, upsert:true, w:1}, function(err, doc) {
              test.equal(null, err);
              test.equal(1, doc.value.d);
              test.equal(1, doc.value.f);

              db.close();
          })
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A whole set of different ways to use the findAndModify command with a Promise..
// The first findAndModify command modifies a document and returns the modified document back.<br>The second findAndModify command removes the document.<br>The second findAndModify command upserts a document and returns the new document.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Create a collection we want to drop later
  var collection = db.collection('simple_find_and_modify_operations_with_promise');
  // Insert some test documentations
  collection.insertMany([{a:1}, {b:1}, {c:1}], {w:1}).then(function(result) {

    // Simple findAndModify command returning the new document
    collection.findAndModify({a:1}, [['a', 1]], {$set:{b1:1}}, {new:true}).then(function(doc) {
      test.equal(1, doc.value.a);
      test.equal(1, doc.value.b1);

      // Simple findAndModify command returning the new document and
      // removing it at the same time
      collection.findAndModify({b:1}, [['b', 1]],
        {$set:{b:2}}, {remove:true}).then(function(doc) {

        // Verify that the document is gone
        collection.findOne({b:1}).then(function(item) {
          test.equal(null, item);

          // Simple findAndModify command performing an upsert and returning the new document
          // executing the command safely
          collection.findAndModify({d:1}, [['b', 1]],
            {d:1, f:1}, {new:true, upsert:true, w:1}).then(function(doc) {
              test.equal(1, doc.value.d);
              test.equal(1, doc.value.f);

              db.close();
          })
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A whole set of different ways to use the findAndModify command with a Generator and the co module..
// The first findAndModify command modifies a document and returns the modified document back.<br>The second findAndModify command removes the document.<br>The second findAndModify command upserts a document and returns the new document.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Create a collection we want to drop later
  var collection = db.collection('simple_find_and_modify_operations_with_generators');
  // Insert some test documentations
  yield collection.insertMany([{a:1}, {b:1}, {c:1}], {w:1});

  // Simple findAndModify command returning the new document
  var doc = yield collection.findAndModify({a:1}, [['a', 1]], {$set:{b1:1}}, {new:true});
  test.equal(1, doc.value.a);
  test.equal(1, doc.value.b1);

  // Simple findAndModify command returning the new document and
  // removing it at the same time
  var doc = yield collection.findAndModify({b:1}, [['b', 1]],
    {$set:{b:2}}, {remove:true});

  // Verify that the document is gone
  var item = yield collection.findOne({b:1});
  test.equal(null, item);

  // Simple findAndModify command performing an upsert and returning the new document
  // executing the command safely
  var doc = yield collection.findAndModify({d:1}, [['b', 1]],
    {d:1, f:1}, {new:true, upsert:true, w:1});
  test.equal(1, doc.value.d);
  test.equal(1, doc.value.f);

  // Close the db
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="findAndRemove">
            
            findAndRemove<span class="signature">(query, sort, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2512">line 2512</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Find and remove a document.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>query</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Query object to locate the object to modify.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>sort</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">array</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>If multiple docs match, choose the first one in the specified sort order as the object to manipulate.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
        <dt class="important tag-deprecated">Deprecated</dt><dd><ul class="dummy"><li>use findOneAndDelete instead</li><ul></dd>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// An example of using findAndRemove

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('simple_find_and_modify_operations_2');
  // Insert some test documentations
  collection.insertMany([{a:1}, {b:1, d:1}, {c:1}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Simple findAndModify command returning the old document and
    // removing it at the same time
    collection.findAndRemove({b:1}, [['b', 1]], function(err, doc) {
      test.equal(null, err);
      test.equal(1, doc.value.b);
      test.equal(1, doc.value.d);

      // Verify that the document is gone
      collection.findOne({b:1}, function(err, item) {
        test.equal(null, err);
        test.equal(null, item);

        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example of using findAndRemove using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('simple_find_and_modify_operations_2_with_promise');
  // Insert some test documentations
  collection.insertMany([{a:1}, {b:1, d:1}, {c:1}], {w:1}).then(function(result) {

    // Simple findAndModify command returning the old document and
    // removing it at the same time
    collection.findAndRemove({b:1}, [['b', 1]]).then(function(doc) {
      test.equal(1, doc.value.b);
      test.equal(1, doc.value.d);

      // Verify that the document is gone
      collection.findOne({b:1}).then(function(item) {
        test.equal(null, item);

        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example of using findAndRemove using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection we want to drop later
  var collection = db.collection('simple_find_and_modify_operations_2_with_generators');
  // Insert some test documentations
  yield collection.insertMany([{a:1}, {b:1, d:1}, {c:1}], {w:1});

  // Simple findAndModify command returning the old document and
  // removing it at the same time
  var doc = yield collection.findAndRemove({b:1}, [['b', 1]]);
  test.equal(1, doc.value.b);
  test.equal(1, doc.value.d);

  // Verify that the document is gone
  var item = yield collection.findOne({b:1});
  test.equal(null, item);

  // Db close
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="findOne">
            
            findOne<span class="signature">(query, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1393">line 1393</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Fetches the first document that matches the query</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>query</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Query for find Operation</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>limit</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    0
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Sets the limit of documents returned in the query.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>sort</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">array</span>
|

<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Set to sort the documents coming back from the query. Array of indexes, [['a', 1]] etc.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>fields</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The fields to return in the query. Object of fields to include or exclude (not both), {'a':1}</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>skip</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    0
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Set to skip N documents ahead in your query (useful for pagination).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>hint</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Tell the query to use specific indexes in the query. Object of indexes to use, {'_id':1}</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>explain</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Explain the query instead of returning the data.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>snapshot</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Snapshot query.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>timeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify if the cursor can timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>tailable</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify if the cursor is tailable.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>batchSize</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    0
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Set the batchSize for the getMoreCommand when iterating over the query results.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>returnKey</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Only return the index key.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>maxScan</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Limit the number of items to scan.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>min</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Set index bounds.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>max</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Set index bounds.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>showDiskLoc</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Show disk location of results.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>comment</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>You can put a $comment field on a query to make looking in the profiler logs simpler.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>raw</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Return document results as raw BSON buffers.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>promoteLongs</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    true
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Promotes Long values to number if they fit inside the 53 bits resolution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>promoteValues</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    true
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Promotes BSON values to native types where possible, set to false to only receive wrapper types.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>promoteBuffers</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Promotes Binary BSON values to native Node Buffers.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>readPreference</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="ReadPreference.html">ReadPreference</a></span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>partial</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify if the cursor should return partial results when querying against a sharded system</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>maxTimeMS</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Number of milliseconds to wait before aborting the query.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>collation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// A simple query using findOne

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('simple_limit_skip_find_one_query');
  // Insert a bunch of documents for the testing
  collection.insertMany([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Perform a simple find and return all the documents
    collection.findOne({a:2}, {fields:{b:1}}, function(err, doc) {
      test.equal(null, err);
      test.equal(null, doc.a);
      test.equal(2, doc.b);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple query using findOne with a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('simple_limit_skip_find_one_query_with_promise');
  // Insert a bunch of documents for the testing
  collection.insertMany([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}).then(function(result) {

    // Perform a simple find and return all the documents
    collection.findOne({a:2}, {fields:{b:1}}).then(function(doc) {
      test.equal(null, doc.a);
      test.equal(2, doc.b);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple query using findOne with a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection we want to drop later
  var collection = db.collection('simple_limit_skip_find_one_query_with_generators');

  // Insert a bunch of documents for the testing
  yield collection.insertMany([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1});

  // Perform a simple find and return all the documents
  var doc = yield collection.findOne({a:2}, {fields:{b:1}});
  test.equal(null, doc.a);
  test.equal(2, doc.b);

  // Db close
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="findOneAndDelete">
            
            findOneAndDelete<span class="signature">(filter, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2234">line 2234</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>filter</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Document selection filter.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>projection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Limits the fields to return for all matching documents.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>sort</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Determines which document the operation modifies if the query selects multiple documents.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>maxTimeMS</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The maximum amount of time to allow the query to run.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~findAndModifyCallback">Collection~findAndModifyCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The collection result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple findOneAndDelete operation

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('find_one_and_delete');
  col.insertMany([{a:1, b:1}], {w:1}, function(err, r) {
    test.equal(null, err);
    test.equal(1, r.result.n);

    col.findOneAndDelete({a:1}
      , { projection: {b:1}, sort: {a:1} }
      , function(err, r) {
        test.equal(null, err);
        test.equal(1, r.lastErrorObject.n);
        test.equal(1, r.value.b);

        db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple findOneAndDelete operation using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('find_one_and_delete_with_promise');
  col.insertMany([{a:1, b:1}], {w:1}).then(function(r) {
    test.equal(1, r.result.n);

    col.findOneAndDelete({a:1}
      , { projection: {b:1}, sort: {a:1} }
      ).then(function(r) {
        test.equal(1, r.lastErrorObject.n);
        test.equal(1, r.value.b);

        db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple findOneAndDelete operation using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Get the collection
  var col = db.collection('find_one_and_delete_with_generators');
  var r = yield col.insertMany([{a:1, b:1}], {w:1});
  test.equal(1, r.result.n);

  var r = yield col.findOneAndDelete({a:1}
    , { projection: {b:1}, sort: {a:1} }
    );
  test.equal(1, r.lastErrorObject.n);
  test.equal(1, r.value.b);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="findOneAndReplace">
            
            findOneAndReplace<span class="signature">(filter, replacement, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2288">line 2288</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>filter</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Document selection filter.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>replacement</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Document replacing the matching document.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>projection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Limits the fields to return for all matching documents.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>sort</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Determines which document the operation modifies if the query selects multiple documents.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>maxTimeMS</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The maximum amount of time to allow the query to run.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>upsert</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Upsert the document if it does not exist.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>returnOriginal</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    true
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>When false, returns the updated document rather than the original. The default is true.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~findAndModifyCallback">Collection~findAndModifyCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The collection result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple findOneAndReplace operation

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('find_one_and_replace');
  col.insertMany([{a:1, b:1}], {w:1}, function(err, r) {
    test.equal(null, err);
    test.equal(1, r.result.n);

    col.findOneAndReplace({a:1}
      , {c:1, b:1}
      , {
            projection: {b:1, c:1}
          , sort: {a:1}
          , returnOriginal: false
          , upsert: true
        }
      , function(err, r) {
        test.equal(null, err);
        test.equal(1, r.lastErrorObject.n);
        test.equal(1, r.value.b);
        test.equal(1, r.value.c);

        db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple findOneAndReplace operation using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('find_one_and_replace_with_promise');
  col.insertMany([{a:1, b:1}], {w:1}).then(function(r) {
    test.equal(1, r.result.n);

    col.findOneAndReplace({a:1}
      , {c:1, b:1}
      , {
            projection: {b:1, c:1}
          , sort: {a:1}
          , returnOriginal: false
          , upsert: true
        }
      ).then(function(r) {
        test.equal(1, r.lastErrorObject.n);
        test.equal(1, r.value.b);
        test.equal(1, r.value.c);

        db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple findOneAndReplace operation using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Get the collection
  var col = db.collection('find_one_and_replace_with_generators');
  var r = yield col.insertMany([{a:1, b:1}], {w:1});
  test.equal(1, r.result.n);

  var r = yield col.findOneAndReplace({a:1}
    , {c:1, b:1}
    , {
          projection: {b:1, c:1}
        , sort: {a:1}
        , returnOriginal: false
        , upsert: true
      }
    );
  test.equal(1, r.lastErrorObject.n);
  test.equal(1, r.value.b);
  test.equal(1, r.value.c);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="findOneAndUpdate">
            
            findOneAndUpdate<span class="signature">(filter, update, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2346">line 2346</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Find a document and update it in one atomic operation, requires a write lock for the duration of the operation.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>filter</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Document selection filter.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>update</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Update operations to be performed on the document</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>projection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Limits the fields to return for all matching documents.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>sort</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Determines which document the operation modifies if the query selects multiple documents.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>maxTimeMS</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The maximum amount of time to allow the query to run.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>upsert</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Upsert the document if it does not exist.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>returnOriginal</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    true
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>When false, returns the updated document rather than the original. The default is true.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~findAndModifyCallback">Collection~findAndModifyCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The collection result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple findOneAndUpdate operation

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('find_one_and_update');
  col.insertMany([{a:1, b:1}], {w:1}, function(err, r) {
    test.equal(null, err);
    test.equal(1, r.result.n);

    col.findOneAndUpdate({a:1}
      , {$set: {d:1}}
      , {
            projection: {b:1, d:1}
          , sort: {a:1}
          , returnOriginal: false
          , upsert: true
        }
      , function(err, r) {
        test.equal(null, err);
        test.equal(1, r.lastErrorObject.n);
        test.equal(1, r.value.b);
        test.equal(1, r.value.d);

        db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple findOneAndUpdate operation using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('find_one_and_update_with_promise');
  col.insertMany([{a:1, b:1}], {w:1}).then(function(r) {
    test.equal(1, r.result.n);

    col.findOneAndUpdate({a:1}
      , {$set: {d:1}}
      , {
            projection: {b:1, d:1}
          , sort: {a:1}
          , returnOriginal: false
          , upsert: true
        }
      ).then(function(r) {
        test.equal(1, r.lastErrorObject.n);
        test.equal(1, r.value.b);
        test.equal(1, r.value.d);

        db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple findOneAndUpdate operation using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Get the collection
  var col = db.collection('find_one_and_update_with_generators');
  var r = yield col.insertMany([{a:1, b:1}], {w:1});
  test.equal(1, r.result.n);

  var r = yield col.findOneAndUpdate({a:1}
    , {$set: {d:1}}
    , {
          projection: {b:1, d:1}
        , sort: {a:1}
        , returnOriginal: false
        , upsert: true
      }
    );
  test.equal(1, r.lastErrorObject.n);
  test.equal(1, r.value.b);
  test.equal(1, r.value.d);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="geoHaystackSearch">
            
            geoHaystackSearch<span class="signature">(x, y, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2898">line 2898</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Execute a geo search using a geo haystack index on a collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>x</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Point to search on the x axis, ensure the indexes are ordered in the same order.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>y</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Point to search on the y axis, ensure the indexes are ordered in the same order.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>readPreference</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="ReadPreference.html">ReadPreference</a></span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>maxDistance</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Include results up to maxDistance from the point.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>search</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Filter the results by a query.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>limit</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Max number of results to return.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple geoHaystackSearch query across some documents

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch the collection
  var collection = db.collection("simple_geo_haystack_command");

  // Add a location based index
  collection.ensureIndex({loc: "geoHaystack", type: 1}, {bucketSize: 1}, function(err, result) {

    // Save a new location tagged document
    collection.insertMany([{a:1, loc:[50, 30]}, {a:1, loc:[30, 50]}], {w:1}, function(err, result) {

      // Use geoNear command to find document
      collection.geoHaystackSearch(50, 50, {search:{a:1}, limit:1, maxDistance:100}, function(err, docs) {
        test.equal(1, docs.results.length);
        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple geoHaystackSearch query across some documents using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch the collection
  var collection = db.collection("simple_geo_haystack_command_with_promise");

  // Add a location based index
  collection.ensureIndex({loc: "geoHaystack", type: 1}, {bucketSize: 1}).then(function(result) {

    // Save a new location tagged document
    collection.insertMany([{a:1, loc:[50, 30]}, {a:1, loc:[30, 50]}], {w:1}).then(function(result) {

      // Use geoNear command to find document
      collection.geoHaystackSearch(50, 50, {search:{a:1}, limit:1, maxDistance:100}).then(function(docs) {
        test.equal(1, docs.results.length);
        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple geoHaystackSearch query across some documents using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Fetch the collection
  var collection = db.collection("simple_geo_haystack_command_with_generators");

  // Add a location based index
  yield collection.ensureIndex({loc: "geoHaystack", type: 1}, {bucketSize: 1});

  // Save a new location tagged document
  yield collection.insertMany([{a:1, loc:[50, 30]}, {a:1, loc:[30, 50]}], {w:1});

  // Use geoNear command to find document
  var docs = yield collection.geoHaystackSearch(50, 50, {search:{a:1}, limit:1, maxDistance:100});
  test.equal(1, docs.results.length);
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="geoNear">
            
            geoNear<span class="signature">(x, y, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2820">line 2820</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Execute the geoNear command to search for items in the collection</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>x</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Point to search on the x axis, ensure the indexes are ordered in the same order.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>y</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Point to search on the y axis, ensure the indexes are ordered in the same order.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>readPreference</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="ReadPreference.html">ReadPreference</a></span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>num</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Max number of results to return.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>minDistance</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Include results starting at minDistance from a point (2.6 or higher)</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>maxDistance</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Include results up to maxDistance from the point.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>distanceMultiplier</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Include a value to multiply the distances with allowing for range conversions.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>query</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Filter the results by a query.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>spherical</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Perform query using a spherical model.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>uniqueDocs</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The closest location in a document to the center of the search region will always be returned MongoDB &gt; 2.X.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>includeLocs</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Include the location data fields in the top level of the results MongoDB &gt; 2.X.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple geoNear query across some documents

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch the collection
  var collection = db.collection("simple_geo_near_command");

  // Add a location based index
  collection.ensureIndex({loc:"2d"}, function(err, result) {

    // Save a new location tagged document
    collection.insertMany([{a:1, loc:[50, 30]}, {a:1, loc:[30, 50]}], {w:1}, function(err, result) {

      // Use geoNear command to find document
      collection.geoNear(50, 50, {query:{a:1}, num:1}, function(err, docs) {
        test.equal(1, docs.results.length);

        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple geoNear query across some documents using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch the collection
  var collection = db.collection("simple_geo_near_command_with_promise");

  // Add a location based index
  collection.ensureIndex({loc:"2d"}).then(function(result) {

    // Save a new location tagged document
    collection.insertMany([{a:1, loc:[50, 30]}, {a:1, loc:[30, 50]}], {w:1}).then(function(result) {

      // Use geoNear command to find document
      collection.geoNear(50, 50, {query:{a:1}, num:1}).then(function(docs) {
        test.equal(1, docs.results.length);

        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple geoNear query across some documents using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Fetch the collection
  var collection = db.collection("simple_geo_near_command_with_generators");

  // Add a location based index
  yield collection.ensureIndex({loc:"2d"});

  // Save a new location tagged document
  yield collection.insertMany([{a:1, loc:[50, 30]}, {a:1, loc:[30, 50]}], {w:1});

  // Use geoNear command to find document
  var docs = yield collection.geoNear(50, 50, {query:{a:1}, num:1});
  test.equal(1, docs.results.length);

  // Close db
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="group">
            
            group<span class="signature">(keys, condition, initial, reduce, finalize, command, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2998">line 2998</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Run a group command across a collection</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>keys</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>
|

<span class="param-type">array</span>
|

<span class="param-type">function</span>
|

<span class="param-type">code</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>An object, array or function expressing the keys to group by.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>condition</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>An optional condition that must be true for a row to be considered.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>initial</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Initial value of the aggregation counter object.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>reduce</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">function</span>
|

<span class="param-type"><a href="Code.html">Code</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The reduce function aggregates (reduces) the objects iterated</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>finalize</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">function</span>
|

<span class="param-type"><a href="Code.html">Code</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>An optional function to be run on each item in the result set just before the item is returned.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>command</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Specify if you wish to run using the internal group command or using eval, default is true.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>readPreference</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="ReadPreference.html">ReadPreference</a></span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
        <dt class="important tag-deprecated">Deprecated</dt><dd><ul class="dummy"><li>MongoDB 3.6 or higher will no longer support the group command. We recommend rewriting using the aggregation framework.</li><ul></dd>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// A whole lot of different ways to execute the group command

var MongoClient = require('mongodb').MongoClient,
  Code = require('mongodb').Code,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection
  var collection = db.collection('test_group');

  // Perform a simple group by on an empty collection
  collection.group([], {}, {"count":0}, "function (obj, prev) { prev.count++; }", function(err, results) {
    test.deepEqual([], results);

    // Trigger some inserts on the collection
    collection.insertMany([{'a':2}, {'b':5}, {'a':1}], {w:1}, function(err, ids) {

      // Perform a group count
      collection.group([], {}, {"count":0}, "function (obj, prev) { prev.count++; }", function(err, results) {
        test.equal(3, results[0].count);

        // Perform a group count using the eval method
        collection.group([], {}, {"count":0}, "function (obj, prev) { prev.count++; }", false, function(err, results) {
          test.equal(3, results[0].count);

          // Group with a conditional
          collection.group([], {'a':{'$gt':1}}, {"count":0}, "function (obj, prev) { prev.count++; }", function(err, results) {
            // Results
            test.equal(1, results[0].count);

            // Group with a conditional using the EVAL method
            collection.group([], {'a':{'$gt':1}}, {"count":0}, "function (obj, prev) { prev.count++; }" , false, function(err, results) {
              // Results
              test.equal(1, results[0].count);

              // Insert some more test data
              collection.insertMany([{'a':2}, {'b':3}], {w:1}, function(err, ids) {

                // Do a Group by field a
                collection.group(['a'], {}, {"count":0}, "function (obj, prev) { prev.count++; }", function(err, results) {
                  // Results
                  test.equal(2, results[0].a);
                  test.equal(2, results[0].count);
                  test.equal(null, results[1].a);
                  test.equal(2, results[1].count);
                  test.equal(1, results[2].a);
                  test.equal(1, results[2].count);

                  // Do a Group by field a
                  collection.group({'a':true}, {}, {"count":0}, function (obj, prev) { prev.count++; }, true, function(err, results) {
                    // Results
                    test.equal(2, results[0].a);
                    test.equal(2, results[0].count);
                    test.equal(null, results[1].a);
                    test.equal(2, results[1].count);
                    test.equal(1, results[2].a);
                    test.equal(1, results[2].count);

                    // Correctly handle illegal function
                    collection.group([], {}, {}, "5 ++ 5", function(err, results) {
                      test.ok(err.message != null);

                      // Use a function to select the keys used to group by
                      var keyf = function(doc) { return {a: doc.a}; };
                      collection.group(keyf, {a: {$gt: 0}}, {"count": 0, "value": 0}, function(obj, prev) { prev.count++; prev.value += obj.a; }, true, function(err, results) {
                        // Results
                        results.sort(function(a, b) { return b.count - a.count; });
                        test.equal(2, results[0].count);
                        test.equal(2, results[0].a);
                        test.equal(4, results[0].value);
                        test.equal(1, results[1].count);
                        test.equal(1, results[1].a);
                        test.equal(1, results[1].value);

                        // Use a Code object to select the keys used to group by
                        var keyf = new Code(function(doc) { return {a: doc.a}; });
                        collection.group(keyf, {a: {$gt: 0}}, {"count": 0, "value": 0}, function(obj, prev) { prev.count++; prev.value += obj.a; }, true, function(err, results) {
                          // Results
                          results.sort(function(a, b) { return b.count - a.count; });
                          test.equal(2, results[0].count);
                          test.equal(2, results[0].a);
                          test.equal(4, results[0].value);
                          test.equal(1, results[1].count);
                          test.equal(1, results[1].a);
                          test.equal(1, results[1].value);

                          // Correctly handle illegal function when using the EVAL method
                          collection.group([], {}, {}, "5 ++ 5", false, function(err, results) {
                            test.ok(err.message != null);

                            db.close();
                          });
                        });
                      });
                    });
                  });
                });
              });
            });
          });
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A whole lot of different ways to execute the group command using a Promise.

var MongoClient = require('mongodb').MongoClient,
  Code = require('mongodb').Code,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection
  var collection = db.collection('test_group_with_promise');

  // Perform a simple group by on an empty collection
  collection.group([], {}, {"count":0}, "function (obj, prev) { prev.count++; }").then(function(results) {
    test.deepEqual([], results);

    // Trigger some inserts on the collection
    collection.insertMany([{'a':2}, {'b':5}, {'a':1}], {w:1}).then(function(ids) {

      // Perform a group count
      collection.group([], {}, {"count":0}, "function (obj, prev) { prev.count++; }").then(function(results) {
        test.equal(3, results[0].count);

        // Perform a group count using the eval method
        collection.group([], {}, {"count":0}, "function (obj, prev) { prev.count++; }", false).then(function(results) {
          test.equal(3, results[0].count);

          // Group with a conditional
          collection.group([], {'a':{'$gt':1}}, {"count":0}, "function (obj, prev) { prev.count++; }").then(function(results) {
            // Results
            test.equal(1, results[0].count);

            // Group with a conditional using the EVAL method
            collection.group([], {'a':{'$gt':1}}, {"count":0}, "function (obj, prev) { prev.count++; }" , false).then(function(results) {
              // Results
              test.equal(1, results[0].count);
              // Insert some more test data
              collection.insertMany([{'a':2}, {'b':3}], {w:1}).then(function(ids) {

                // Do a Group by field a
                collection.group(['a'], {}, {"count":0}, "function (obj, prev) { prev.count++; }").then(function(results) {
                  // Results
                  test.equal(2, results[0].a);
                  test.equal(2, results[0].count);
                  test.equal(null, results[1].a);
                  test.equal(2, results[1].count);
                  test.equal(1, results[2].a);
                  test.equal(1, results[2].count);

                  // Do a Group by field a
                  collection.group({'a':true}, {}, {"count":0}, function (obj, prev) { prev.count++; }, true).then(function(results) {
                    // Results
                    test.equal(2, results[0].a);
                    test.equal(2, results[0].count);
                    test.equal(null, results[1].a);
                    test.equal(2, results[1].count);
                    test.equal(1, results[2].a);
                    test.equal(1, results[2].count);

                    // Correctly handle illegal function
                    collection.group([], {}, {}, "5 ++ 5").then(function(err, results) {
                    }).catch(function(err) {
                      test.ok(err.message != null);

                      // Use a function to select the keys used to group by
                      var keyf = function(doc) { return {a: doc.a}; };
                      collection.group(keyf, {a: {$gt: 0}}, {"count": 0, "value": 0}, function(obj, prev) { prev.count++; prev.value += obj.a; }, true).then(function(results) {
                        // Results
                        results.sort(function(a, b) { return b.count - a.count; });
                        test.equal(2, results[0].count);
                        test.equal(2, results[0].a);
                        test.equal(4, results[0].value);
                        test.equal(1, results[1].count);
                        test.equal(1, results[1].a);
                        test.equal(1, results[1].value);

                        // Use a Code object to select the keys used to group by
                        var keyf = new Code(function(doc) { return {a: doc.a}; });
                        collection.group(keyf, {a: {$gt: 0}}, {"count": 0, "value": 0}, function(obj, prev) { prev.count++; prev.value += obj.a; }, true).then(function(results) {
                          // Results
                          results.sort(function(a, b) { return b.count - a.count; });
                          test.equal(2, results[0].count);
                          test.equal(2, results[0].a);
                          test.equal(4, results[0].value);
                          test.equal(1, results[1].count);
                          test.equal(1, results[1].a);
                          test.equal(1, results[1].value);

                          // Correctly handle illegal function when using the EVAL method
                          collection.group([], {}, {}, "5 ++ 5", false).then(function(results) {
                          }).catch(function(err) {
                            test.ok(err.message != null);

                            db.close();
                          });
                        });
                      });
                    });
                  });
                });
              });
            });
          });
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A whole lot of different ways to execute the group command using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  Code = require('mongodb').Code;
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a test collection
  var collection = db.collection('test_group_with_generators');

  // Perform a simple group by on an empty collection
  var results = yield collection.group([], {}, {"count":0}, "function (obj, prev) { prev.count++; }");
  test.deepEqual([], results);

  // Trigger some inserts on the collection
  yield collection.insertMany([{'a':2}, {'b':5}, {'a':1}], {w:1});

  // Perform a group count
  var results = yield collection.group([], {}, {"count":0}, "function (obj, prev) { prev.count++; }");
  test.equal(3, results[0].count);

  // Perform a group count using the eval method
  var results = yield collection.group([], {}, {"count":0}, "function (obj, prev) { prev.count++; }", false);
  test.equal(3, results[0].count);

  // Group with a conditional
  var results = yield collection.group([], {'a':{'$gt':1}}, {"count":0}, "function (obj, prev) { prev.count++; }");
  // Results
  test.equal(1, results[0].count);

  // Group with a conditional using the EVAL method
  var results = yield collection.group([], {'a':{'$gt':1}}, {"count":0}, "function (obj, prev) { prev.count++; }" , false);
  // Results
  test.equal(1, results[0].count);

  // Insert some more test data
  yield collection.insertMany([{'a':2}, {'b':3}], {w:1});

  // Do a Group by field a
  var results = yield collection.group(['a'], {}, {"count":0}, "function (obj, prev) { prev.count++; }");
  // Results
  test.equal(2, results[0].a);
  test.equal(2, results[0].count);
  test.equal(null, results[1].a);
  test.equal(2, results[1].count);
  test.equal(1, results[2].a);
  test.equal(1, results[2].count);

  // Do a Group by field a
  var results = yield collection.group({'a':true}, {}, {"count":0}, function (obj, prev) { prev.count++; }, true);
  // Results
  test.equal(2, results[0].a);
  test.equal(2, results[0].count);
  test.equal(null, results[1].a);
  test.equal(2, results[1].count);
  test.equal(1, results[2].a);
  test.equal(1, results[2].count);

  try {
    // Correctly handle illegal function
    var results = yield collection.group([], {}, {}, "5 ++ 5")
  } catch(err) {
    test.ok(err.message != null);

    // Use a function to select the keys used to group by
    var keyf = function(doc) { return {a: doc.a}; };
    var results = yield collection.group(keyf, {a: {$gt: 0}}, {"count": 0, "value": 0}, function(obj, prev) { prev.count++; prev.value += obj.a; }, true);
    // Results
    results.sort(function(a, b) { return b.count - a.count; });
    test.equal(2, results[0].count);
    test.equal(2, results[0].a);
    test.equal(4, results[0].value);
    test.equal(1, results[1].count);
    test.equal(1, results[1].a);
    test.equal(1, results[1].value);

    // Use a Code object to select the keys used to group by
    var keyf = new Code(function(doc) { return {a: doc.a}; });
    var results = yield collection.group(keyf, {a: {$gt: 0}}, {"count": 0, "value": 0}, function(obj, prev) { prev.count++; prev.value += obj.a; }, true);
    // Results
    results.sort(function(a, b) { return b.count - a.count; });
    test.equal(2, results[0].count);
    test.equal(2, results[0].a);
    test.equal(4, results[0].value);
    test.equal(1, results[1].count);
    test.equal(1, results[1].a);
    test.equal(1, results[1].value);

    try {
      yield collection.group([], {}, {}, "5 ++ 5", false);
    } catch(err) {
      test.ok(err.message != null);

      db.close();
    }
  };
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="indexes">
            
            indexes<span class="signature">(<span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2140">line 2140</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Retrieve all the indexes on the collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of retrieving a collections indexes

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Crete the collection for the distinct example
  var collection = db.collection('simple_key_based_distinct');
  // Create a geo 2d index
  collection.ensureIndex({loc:"2d"}, {w:1}, function(err, result) {
    test.equal(null, err);

    // Create a simple single field index
    collection.ensureIndex({a:1}, {w:1}, function(err, result) {
      test.equal(null, err);

      setTimeout(function() {
        // List all of the indexes on the collection
        collection.indexes(function(err, indexes) {
          test.equal(3, indexes.length);

          db.close();
        });
      }, 1000);
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of retrieving a collections indexes using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Crete the collection for the distinct example
  var collection = db.collection('simple_key_based_distinct_with_promise');

  // Create a geo 2d index
  collection.ensureIndex({loc:"2d"}, {w:1}).then(function(result) {

    // Create a simple single field index
    collection.ensureIndex({a:1}, {w:1}).then(function(result) {

      setTimeout(function() {
        // List all of the indexes on the collection
        collection.indexes().then(function(indexes) {
          test.equal(3, indexes.length);

          db.close();
        });
      }, 1000);
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of retrieving a collections indexes using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Crete the collection for the distinct example
  var collection = db.collection('simple_key_based_distinct_with_generators');

  // Create a geo 2d index
  yield collection.ensureIndex({loc:"2d"}, {w:1});

  // Create a simple single field index
  yield collection.ensureIndex({a:1}, {w:1});

  setTimeout(function() {
    co(function*() {
      // List all of the indexes on the collection
      var indexes = yield collection.indexes()
      test.equal(3, indexes.length);

      db.close();
    });
  }, 1000);
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="indexExists">
            
            indexExists<span class="signature">(indexes, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1914">line 1914</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Checks if one or more indexes exist on the collection, fails on first non-existing index</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>indexes</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>
|

<span class="param-type">array</span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>One or more index names to check.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// An example showing the use of the indexExists function for a single index name and a list of index names.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Create a test collection that we are getting the options back from
  var collection = db.collection('test_collection_index_exists', {w:1});
  test.equal(null, err);
  // Create an index on the collection
  collection.createIndex('a', {w:1}, function(err, indexName) {
    // Let's test to check if a single index exists
    collection.indexExists("a_1", function(err, result) {
      test.equal(true, result);

      // Let's test to check if multiple indexes are available
      collection.indexExists(["a_1", "_id_"], function(err, result) {
        test.equal(true, result);

        // Check if a non existing index exists
        collection.indexExists("c_1", function(err, result) {
          test.equal(false, result);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example showing the use of the indexExists function using a Promise for a single index name and a list of index names.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Create a test collection that we are getting the options back from
  var collection = db.collection('test_collection_index_exists_with_promise', {w:1});
  // Create an index on the collection
  collection.createIndex('a', {w:1}).then(function(indexName) {
    // Let's test to check if a single index exists
    collection.indexExists("a_1").then(function(result) {
      test.equal(true, result);

      // Let's test to check if multiple indexes are available
      collection.indexExists(["a_1", "_id_"]).then(function(result) {
        test.equal(true, result);

        // Check if a non existing index exists
        collection.indexExists("c_1").then(function(result) {
          test.equal(false, result);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example showing the use of the indexExists function using a Generator and the co module for a single index name and a list of index names.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Create a test collection that we are getting the options back from
  var collection = db.collection('test_collection_index_exists_with_generators', {w:1});
  // Create an index on the collection
  yield collection.createIndex('a', {w:1});

  // Let's test to check if a single index exists
  var result = yield collection.indexExists("a_1");
  test.equal(true, result);

  // Let's test to check if multiple indexes are available
  var result = yield collection.indexExists(["a_1", "_id_"]);
  test.equal(true, result);

  // Check if a non existing index exists
  var result = yield collection.indexExists("c_1");
  test.equal(false, result);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="indexInformation">
            
            indexInformation<span class="signature">(<span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1957">line 1957</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Retrieves this collections index info.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>full</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Returns the full raw index information.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// An example showing the information returned by indexInformation

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('more_index_information_test_2');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}, function(err, indexName) {
      test.equal(null, err);
      // Fetch basic indexInformation for collection
      db.indexInformation('more_index_information_test_2', function(err, indexInformation) {
        test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
        test.deepEqual([ [ 'a', 1 ], [ 'b', 1 ] ], indexInformation.a_1_b_1);

        // Fetch full index information
        collection.indexInformation({full:true}, function(err, indexInformation) {
          test.deepEqual({ _id: 1 }, indexInformation[0].key);
          test.deepEqual({ a: 1, b: 1 }, indexInformation[1].key);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An examples showing the information returned by indexInformation

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('more_index_information_test_3');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}, function(err, indexName) {
      test.equal(null, err);

      // Fetch basic indexInformation for collection
      collection.indexInformation(function(err, indexInformation) {
        test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
        test.deepEqual([ [ 'a', 1 ], [ 'b', 1 ] ], indexInformation.a_1_b_1);

        // Fetch full index information
        collection.indexInformation({full:true}, function(err, indexInformation) {
          test.deepEqual({ _id: 1 }, indexInformation[0].key);
          test.deepEqual({ a: 1, b: 1 }, indexInformation[1].key);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example showing the information returned by indexInformation using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('more_index_information_test_2_with_promise');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}).then(function(result) {

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}).then(function(indexName) {
      // Fetch basic indexInformation for collection
      db.indexInformation('more_index_information_test_2_with_promise').then(function(indexInformation) {
        test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
        test.deepEqual([ [ 'a', 1 ], [ 'b', 1 ] ], indexInformation.a_1_b_1);

        // Fetch full index information
        collection.indexInformation({full:true}).then(function(indexInformation) {
          test.deepEqual({ _id: 1 }, indexInformation[0].key);
          test.deepEqual({ a: 1, b: 1 }, indexInformation[1].key);

          db.close();
        });
      }).catch(function(err) {
        console.dir(err)
      });
    });
  }).catch(function(err) {
    console.dir(err)
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An examples showing the information returned by indexInformation using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('more_index_information_test_3_with_promise');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}).then(function(result) {

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}).then(function(indexName) {

      // Fetch basic indexInformation for collection
      collection.indexInformation().then(function(indexInformation) {
        test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
        test.deepEqual([ [ 'a', 1 ], [ 'b', 1 ] ], indexInformation.a_1_b_1);

        // Fetch full index information
        collection.indexInformation({full:true}).then(function(indexInformation) {
          test.deepEqual({ _id: 1 }, indexInformation[0].key);
          test.deepEqual({ a: 1, b: 1 }, indexInformation[1].key);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example showing the information returned by indexInformation using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection we want to drop later
  var collection = db.collection('more_index_information_test_2_with_generators');
  // Insert a bunch of documents for the index
  yield collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1});

  // Create an index on the a field
  yield collection.ensureIndex({a:1, b:1}
    , {unique:true, background:true, w:1});

  // Fetch basic indexInformation for collection
  var indexInformation = yield db.indexInformation('more_index_information_test_2_with_generators');
  test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
  test.deepEqual([ [ 'a', 1 ], [ 'b', 1 ] ], indexInformation.a_1_b_1);

  // Fetch full index information
  var indexInformation = yield collection.indexInformation({full:true});
  test.deepEqual({ _id: 1 }, indexInformation[0].key);
  test.deepEqual({ a: 1, b: 1 }, indexInformation[1].key);

  // Close db
  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An examples showing the information returned by indexInformation using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection we want to drop later
  var collection = db.collection('more_index_information_test_3_with_generators');
  // Insert a bunch of documents for the index
  yield collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1});

  // Create an index on the a field
  yield collection.ensureIndex({a:1, b:1}
    , {unique:true, background:true, w:1});

  // Fetch basic indexInformation for collection
  var indexInformation = yield collection.indexInformation();
  test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
  test.deepEqual([ [ 'a', 1 ], [ 'b', 1 ] ], indexInformation.a_1_b_1);

  // Fetch full index information
  var indexInformation = yield collection.indexInformation({full:true});
  test.deepEqual({ _id: 1 }, indexInformation[0].key);
  test.deepEqual({ a: 1, b: 1 }, indexInformation[1].key);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="initializeOrderedBulkOp">
            
            initializeOrderedBulkOp<span class="signature">(<span class="optional">options</span>, callback)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{null}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line3318">line 3318</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Initiate an In order bulk write operation, operations will be serially executed in the order they are added, creating a new operation for each switch in types.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="OrderedBulkOperation.html">OrderedBulkOperation</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple ordered insert/update/upsert/remove ordered collection

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('batch_write_ordered_ops_0');
  // Initialize the Ordered Batch
  var batch = col.initializeOrderedBulkOp();
  // Add some operations to be executed in order
  batch.insert({a:1});
  batch.find({a:1}).updateOne({$set: {b:1}});
  batch.find({a:2}).upsert().updateOne({$set: {b:2}});
  batch.insert({a:3});
  batch.find({a:3}).remove({a:3});

  // Execute the operations
  batch.execute(function(err, result) {
    // Check state of result
    test.equal(2, result.nInserted);
    test.equal(1, result.nUpserted);
    test.equal(1, result.nMatched);
    test.ok(1 == result.nModified || result.nModified == null);
    test.equal(1, result.nRemoved);

    var upserts = result.getUpsertedIds();
    test.equal(1, upserts.length);
    test.equal(2, upserts[0].index);
    test.ok(upserts[0]._id != null);

    var upsert = result.getUpsertedIdAt(0);
    test.equal(2, upsert.index);
    test.ok(upsert._id != null);

    // Finish up test
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple ordered insert/update/upsert/remove ordered collection using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('batch_write_ordered_ops_0_with_promise');
  // Initialize the Ordered Batch
  var batch = col.initializeOrderedBulkOp();
  // Add some operations to be executed in order
  batch.insert({a:1});
  batch.find({a:1}).updateOne({$set: {b:1}});
  batch.find({a:2}).upsert().updateOne({$set: {b:2}});
  batch.insert({a:3});
  batch.find({a:3}).remove({a:3});

  // Execute the operations
  batch.execute().then(function(result) {
    // Check state of result
    test.equal(2, result.nInserted);
    test.equal(1, result.nUpserted);
    test.equal(1, result.nMatched);
    test.ok(1 == result.nModified || result.nModified == 0 || result.nModified == null);
    test.equal(1, result.nRemoved);

    var upserts = result.getUpsertedIds();
    test.equal(1, upserts.length);
    test.equal(2, upserts[0].index);
    test.ok(upserts[0]._id != null);

    var upsert = result.getUpsertedIdAt(0);
    test.equal(2, upsert.index);
    test.ok(upsert._id != null);

    // Finish up test
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple ordered insert/update/upsert/remove ordered collection using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Get the collection
  var col = db.collection('batch_write_ordered_ops_0_with_generators');
  // Initialize the Ordered Batch
  var batch = col.initializeOrderedBulkOp();
  // Add some operations to be executed in order
  batch.insert({a:1});
  batch.find({a:1}).updateOne({$set: {b:1}});
  batch.find({a:2}).upsert().updateOne({$set: {b:2}});
  batch.insert({a:3});
  batch.find({a:3}).remove({a:3});

  // Execute the operations
  var result = yield batch.execute();
  // Check state of result
  test.equal(2, result.nInserted);
  test.equal(1, result.nUpserted);
  test.equal(1, result.nMatched);
  test.ok(1 == result.nModified || result.nModified == null);
  test.equal(1, result.nRemoved);

  var upserts = result.getUpsertedIds();
  test.equal(1, upserts.length);
  test.equal(2, upserts[0].index);
  test.ok(upserts[0]._id != null);

  var upsert = result.getUpsertedIdAt(0);
  test.equal(2, upsert.index);
  test.ok(upsert._id != null);

  // Finish up test
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="initializeUnorderedBulkOp">
            
            initializeUnorderedBulkOp<span class="signature">(<span class="optional">options</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{<a href="UnorderedBulkOperation.html">UnorderedBulkOperation</a>}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line3299">line 3299</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple ordered insert/update/upsert/remove ordered collection

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('batch_write_unordered_ops_legacy_0');
  // Initialize the unordered Batch
  var batch = col.initializeUnorderedBulkOp();

  // Add some operations to be executed in order
  batch.insert({a:1});
  batch.find({a:1}).updateOne({$set: {b:1}});
  batch.find({a:2}).upsert().updateOne({$set: {b:2}});
  batch.insert({a:3});
  batch.find({a:3}).remove({a:3});

  // Execute the operations
  batch.execute(function(err, result) {
    // Check state of result
    test.equal(2, result.nInserted);
    test.equal(1, result.nUpserted);
    test.equal(1, result.nMatched);
    test.ok(1 == result.nModified || result.nModified == null);
    test.equal(1, result.nRemoved);

    var upserts = result.getUpsertedIds();
    test.equal(1, upserts.length);
    test.equal(2, upserts[0].index);
    test.ok(upserts[0]._id != null);

    var upsert = result.getUpsertedIdAt(0);
    test.equal(2, upsert.index);
    test.ok(upsert._id != null);

    // Finish up test
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple ordered insert/update/upsert/remove ordered collection using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('batch_write_unordered_ops_legacy_0_with_promise');
  // Initialize the unordered Batch
  var batch = col.initializeUnorderedBulkOp();

  // Add some operations to be executed in order
  batch.insert({a:1});
  batch.find({a:1}).updateOne({$set: {b:1}});
  batch.find({a:2}).upsert().updateOne({$set: {b:2}});
  batch.insert({a:3});
  batch.find({a:3}).remove({a:3});

  // Execute the operations
  batch.execute().then(function(result) {
    // Check state of result
    test.equal(2, result.nInserted);
    test.equal(1, result.nUpserted);
    test.equal(1, result.nMatched);
    test.ok(1 == result.nModified || result.nModified == 0 || result.nModified == null);
    test.equal(1, result.nRemoved);

    var upserts = result.getUpsertedIds();
    test.equal(1, upserts.length);
    test.equal(2, upserts[0].index);
    test.ok(upserts[0]._id != null);

    var upsert = result.getUpsertedIdAt(0);
    test.equal(2, upsert.index);
    test.ok(upsert._id != null);

    // Finish up test
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple ordered insert/update/upsert/remove ordered collection using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Get the collection
  var col = db.collection('batch_write_unordered_ops_legacy_0_with_generators');
  // Initialize the unordered Batch
  var batch = col.initializeUnorderedBulkOp({useLegacyOps: true});

  // Add some operations to be executed in order
  batch.insert({a:1});
  batch.find({a:1}).updateOne({$set: {b:1}});
  batch.find({a:2}).upsert().updateOne({$set: {b:2}});
  batch.insert({a:3});
  batch.find({a:3}).remove({a:3});

  // Execute the operations
  var result = yield batch.execute();
  // Check state of result
  test.equal(2, result.nInserted);
  test.equal(1, result.nUpserted);
  test.equal(1, result.nMatched);
  test.ok(1 == result.nModified || result.nModified == null);
  test.equal(1, result.nRemoved);

  var upserts = result.getUpsertedIds();
  test.equal(1, upserts.length);
  test.equal(2, upserts[0].index);
  test.ok(upserts[0]._id != null);

  var upsert = result.getUpsertedIdAt(0);
  test.equal(2, upsert.index);
  test.ok(upsert._id != null);

  // Finish up test
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="insert">
            
            insert<span class="signature">(docs, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line826">line 826</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Inserts a single document or a an array of documents into MongoDB. If documents passed in do not contain the <strong>_id</strong> field,<br>one will be added to each of the documents missing it by the driver, mutating the document. This behavior<br>can be overridden by setting the <strong>forceServerObjectId</strong> flag.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>docs</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>
|

<span class="param-type">Array.&lt;object></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Documents to insert.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>serializeFunctions</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Serialize functions on any object.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>forceServerObjectId</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Force server to assign _id values instead of driver.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>bypassDocumentValidation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allow driver to bypass schema validation in MongoDB 3.2 or higher.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~insertWriteOpCallback">Collection~insertWriteOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
        <dt class="important tag-deprecated">Deprecated</dt><dd><ul class="dummy"><li>Use insertOne, insertMany or bulkWrite</li><ul></dd>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// A simple document insert example, not using safe mode to ensure document persistance on MongoDB

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var collection = db.collection("simple_document_insert_collection_no_safe");
  // Insert a single document
  collection.insertOne({hello:'world_no_safe'});

  // Wait for a second before finishing up, to ensure we have written the item to disk
  setTimeout(function() {

    // Fetch the document
    collection.findOne({hello:'world_no_safe'}, function(err, item) {
      test.equal(null, err);
      test.equal('world_no_safe', item.hello);
      db.close();
    })
  }, 100);
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A batch document insert example, using safe mode to ensure document persistance on MongoDB

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Fetch a collection to insert document into
  var collection = db.collection("batch_document_insert_collection_safe");
  // Insert a single document
  collection.insertMany([{hello:'world_safe1'}
    , {hello:'world_safe2'}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Fetch the document
    collection.findOne({hello:'world_safe2'}, function(err, item) {
      test.equal(null, err);
      test.equal('world_safe2', item.hello);
      db.close();
    })
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of inserting a document containing functions

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Fetch a collection to insert document into
  var collection = db.collection("simple_document_insert_with_function_safe");

  var o = {w:1};
  o.serializeFunctions = true;
  // Insert a single document
  collection.insertOne({hello:'world'
    , func:function() {}}, o, function(err, result) {
    test.equal(null, err);

    // Fetch the document
    collection.findOne({hello:'world'}, function(err, item) {
      test.equal(null, err);
      test.ok("function() {}", item.code);
      db.close();
    })
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of using keepGoing to allow batch insert to complete even when there are illegal documents in the batch

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection
  var collection = db.collection('keepGoingExample');

  // Add an unique index to title to force errors in the batch insert
  collection.ensureIndex({title:1}, {unique:true}, function(err, indexName) {

    // Insert some intial data into the collection
    collection.insertMany([{name:"Jim"}
      , {name:"Sarah", title:"Princess"}], {w:1}, function(err, result) {

      // Force keep going flag, ignoring unique index issue
      collection.insert([{name:"Jim"}
        , {name:"Sarah", title:"Princess"}
        , {name:'Gump', title:"Gump"}], {w:1, keepGoing:true}, function(err, result) {

        // Count the number of documents left (should not include the duplicates)
        collection.count(function(err, count) {
          test.equal(3, count);
          db.close();
        })
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple document insert using a Promise example, not using safe mode to ensure document persistance on MongoDB

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var collection = db.collection("simple_document_insert_collection_no_safe_with_promise");
  // Insert a single document
  collection.insertOne({hello:'world_no_safe'});

  // Wait for a second before finishing up, to ensure we have written the item to disk
  setTimeout(function() {

    // Fetch the document
    collection.findOne({hello:'world_no_safe'}).then(function(item) {
      test.equal('world_no_safe', item.hello);
      db.close();
    })
  }, 100);
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A batch document insert using a Promise example, using safe mode to ensure document persistance on MongoDB

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Fetch a collection to insert document into
  var collection = db.collection("batch_document_insert_collection_safe_with_promise");
  // Insert a single document
  collection.insertMany([{hello:'world_safe1'}
    , {hello:'world_safe2'}], {w:1}).then(function(result) {

    // Fetch the document
    collection.findOne({hello:'world_safe2'}).then(function(item) {
      test.equal('world_safe2', item.hello);
      db.close();
    })
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of inserting a document containing functions using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Fetch a collection to insert document into
  var collection = db.collection("simple_document_insert_with_function_safe_with_promise");

  var o = {w:1};
  o.serializeFunctions = true;
  // Insert a single document
  collection.insertOne({hello:'world'
    , func:function() {}}, o).then(function(result) {

    // Fetch the document
    collection.findOne({hello:'world'}).then(function(item) {
      test.ok("function() {}", item.code);
      db.close();
    })
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of using keepGoing to allow batch insert using a Promise to complete even when there are illegal documents in the batch

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection
  var collection = db.collection('keepGoingExample_with_promise');
  collection.drop(function() {
    // Add an unique index to title to force errors in the batch insert
    collection.ensureIndex({title:1}, {unique:true}).then(function(indexName) {

      // Insert some intial data into the collection
      collection.insertMany([{name:"Jim"}
        , {name:"Sarah", title:"Princess"}], {w:1}).then(function(result) {

        // Force keep going flag, ignoring unique index issue
        collection.insert([{name:"Jim"}
          , {name:"Sarah", title:"Princess"}
          , {name:'Gump', title:"Gump"}], {w:1, keepGoing:true}).then(function(result) {
          }).catch(function(err) {
          // Count the number of documents left (should not include the duplicates)
          collection.count().then(function(count) {
            test.equal(3, count);
          })
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple document insert using a Generator and the co module example, not using safe mode to ensure document persistance on MongoDB

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  var collection = db.collection("simple_document_insert_collection_no_safe_with_generators");
  // Insert a single document
  collection.insertOne({hello:'world_no_safe'});

  // Wait for a second before finishing up, to ensure we have written the item to disk
  setTimeout(function() {
    co(function*() {
      // Fetch the document
      var item = yield collection.findOne({hello:'world_no_safe'});
      test.equal('world_no_safe', item.hello);
      db.close();
    })
  }, 100);
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A batch document insert using a Generator and the co module example, using safe mode to ensure document persistance on MongoDB

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Fetch a collection to insert document into
  var collection = db.collection("batch_document_insert_collection_safe_with_generators");

  // Insert a single document
  yield collection.insertMany([{hello:'world_safe1'}
    , {hello:'world_safe2'}], {w:1});

  // Fetch the document
  var item = yield collection.findOne({hello:'world_safe2'});
  test.equal('world_safe2', item.hello);
  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of inserting a document containing functions using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Fetch a collection to insert document into
  var collection = db.collection("simple_document_insert_with_function_safe_with_generators");

  // Get the option
  var o = {w:1};
  o.serializeFunctions = true;

  // Insert a single document
  yield collection.insertOne({hello:'world', func:function() {}}, o);

  // Fetch the document
  var item = yield collection.findOne({hello:'world'});
  test.ok("function() {}", item.code);
  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of using keepGoing to allow batch insert using a Generator and the co module to complete even when there are illegal documents in the batch

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection
  var collection = db.collection('keepGoingExample_with_generators');

  // Add an unique index to title to force errors in the batch insert
  yield collection.ensureIndex({title:1}, {unique:true});

  // Insert some intial data into the collection
  yield collection.insertMany([{name:"Jim"}
    , {name:"Sarah", title:"Princess"}], {w:1});

  try {
    // Force keep going flag, ignoring unique index issue
    yield collection.insert([{name:"Jim"}
      , {name:"Sarah", title:"Princess"}
      , {name:'Gump', title:"Gump"}], {w:1, keepGoing:true});
  } catch(err) {}
  // Count the number of documents left (should not include the duplicates)
  var count = yield collection.count();
  test.equal(3, count);
}).catch(function(err) {
  console.log(err.stack)
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="insertMany">
            
            insertMany<span class="signature">(docs, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line495">line 495</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Inserts an array of documents into MongoDB. If documents passed in do not contain the <strong>_id</strong> field,<br>one will be added to each of the documents missing it by the driver, mutating the document. This behavior<br>can be overridden by setting the <strong>forceServerObjectId</strong> flag.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>docs</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Array.&lt;object></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Documents to insert.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>serializeFunctions</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Serialize functions on any object.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>forceServerObjectId</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Force server to assign _id values instead of driver.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>bypassDocumentValidation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allow driver to bypass schema validation in MongoDB 3.2 or higher.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>ordered</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    true
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~insertWriteOpCallback">Collection~insertWriteOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple insertMany operation

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('insert_many');
  col.insertMany([{a:1}, {a:2}], function(err, r) {
    test.equal(null, err);
    test.equal(2, r.insertedCount);
    // Finish up test
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple insertMany operation using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('insert_many_with_promise');
  col.insertMany([{a:1}, {a:2}]).then(function(r) {
    test.equal(2, r.insertedCount);
    // Finish up test
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple insertMany operation using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Get the collection
  var col = db.collection('insert_many_with_generators');
  var r = yield col.insertMany([{a:1}, {a:2}]);
  test.equal(2, r.insertedCount);
  // Finish up test
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="insertOne">
            
            insertOne<span class="signature">(doc, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line407">line 407</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Inserts a single document into MongoDB. If documents passed in do not contain the <strong>_id</strong> field,<br>one will be added to each of the documents missing it by the driver, mutating the document. This behavior<br>can be overridden by setting the <strong>forceServerObjectId</strong> flag.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>doc</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Document to insert.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>serializeFunctions</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Serialize functions on any object.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>forceServerObjectId</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Force server to assign _id values instead of driver.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>bypassDocumentValidation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allow driver to bypass schema validation in MongoDB 3.2 or higher.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~insertOneWriteOpCallback">Collection~insertOneWriteOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple insertOne operation

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('insert_one');
  col.insertOne({a:1}, function(err, r) {
    test.equal(null, err);
    test.equal(1, r.insertedCount);
    // Finish up test
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple insertOne operation using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('insert_one_with_promise');
  col.insertOne({a:1}).then(function(r) {
    test.equal(1, r.insertedCount);
    // Finish up test
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple insertOne operation using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Get the collection
  var col = db.collection('insert_one_with_generators');
  var r = yield col.insertOne({a:1});
  test.equal(1, r.insertedCount);
  // Finish up test
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="isCapped">
            
            isCapped<span class="signature">(<span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1551">line 1551</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Returns if the collection is a capped collection</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The results callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// An example showing how to establish if it's a capped collection

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection that we are getting the options back from
  db.createCollection('test_collection_is_capped', {'capped':true, 'size':1024}, function(err, collection) {
    test.equal('test_collection_is_capped', collection.collectionName);

    // Let's fetch the collection options
    collection.isCapped(function(err, capped) {
      test.equal(true, capped);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example showing how to establish if it's a capped collection using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection that we are getting the options back from
  db.createCollection('test_collection_is_capped_with_promise', {'capped':true, 'size':1024}).then(function(collection) {
    test.equal('test_collection_is_capped_with_promise', collection.collectionName);

    // Let's fetch the collection options
    collection.isCapped().then(function(capped) {
      test.equal(true, capped);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example showing how to establish if it's a capped collection using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a test collection that we are getting the options back from
  var collection = yield db.createCollection('test_collection_is_capped_with_generators', {'capped':true, 'size':1024});
  test.equal('test_collection_is_capped_with_generators', collection.collectionName);

  // Let's fetch the collection options
  var capped = yield collection.isCapped();
  test.equal(true, capped);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="listIndexes">
            
            listIndexes<span class="signature">(<span class="optional">options</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{<a href="CommandCursor.html">CommandCursor</a>}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1819">line 1819</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Get the list of all indexes information for the collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>batchSize</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The batchSize for the returned command cursor or if pre 2.8 the systems batch collection</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>readPreference</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="ReadPreference.html">ReadPreference</a></span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="mapReduce">
            
            mapReduce<span class="signature">(map, reduce, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line3162">line 3162</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>map</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">function</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The mapping function.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>reduce</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">function</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The reduce function.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>readPreference</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="ReadPreference.html">ReadPreference</a></span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>out</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Sets the output target for the map reduce job. <em>{inline:1} | {replace:'collectionName'} | {merge:'collectionName'} | {reduce:'collectionName'}</em></p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>query</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Query filter object.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>sort</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>limit</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Number of objects to return from collection.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>keeptemp</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Keep temporary data.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>finalize</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">function</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Finalize function.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>scope</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Can pass in variables that can be access from map/reduce/finalize.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>jsMode</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>It is possible to make the execution stay in JS. Provided in MongoDB &gt; 2.0.X.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>verbose</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Provide statistics on job execution time.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>bypassDocumentValidation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allow driver to bypass schema validation in MongoDB 3.2 or higher.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    <h5>Throws:</h5>
    
            

    <div class="param-desc">
    
        
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


    
    </div>


        
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// A simple map reduce example

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions');

  // Insert some documents to perform map reduce over
  collection.insertMany([{'user_id':1}, {'user_id':2}], {w:1}, function(err, r) {

    // Map function
    var map = function() { emit(this.user_id, 1); };
    // Reduce function
    var reduce = function(k,vals) { return 1; };

    // Perform the map reduce
    collection.mapReduce(map, reduce, {out: {replace : 'tempCollection'}}, function(err, collection) {
      test.equal(null, err);

      // Mapreduce returns the temporary collection with the results
      collection.findOne({'_id':1}, function(err, result) {
        test.equal(1, result.value);

        collection.findOne({'_id':2}, function(err, result) {
          test.equal(1, result.value);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple map reduce example using the inline output type on MongoDB &gt; 1.7.6 returning the statistics

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_inline');

  // Insert some test documents
  collection.insertMany([{'user_id':1}, {'user_id':2}], {w:1}, function(err, r) {

    // Map function
    var map = function() { emit(this.user_id, 1); };
    // Reduce function
    var reduce = function(k,vals) { return 1; };

    // Execute map reduce and return results inline
    collection.mapReduce(map, reduce, {out : {inline: 1}, verbose:true}, function(err, results, stats) {
      test.equal(2, results.length);
      test.ok(stats != null);

      collection.mapReduce(map, reduce, {out : {replace: 'mapreduce_integration_test'}, verbose:true}, function(err, results, stats) {
        test.ok(stats != null);
        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Mapreduce different test with a provided scope containing a javascript function.

var MongoClient = require('mongodb').MongoClient,
  Code = require('mongodb').Code,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_scope');

  // Insert some test documents
  collection.insertMany([{'user_id':1, 'timestamp':new Date()}
    , {'user_id':2, 'timestamp':new Date()}], {w:1}, function(err, r) {

    // Map function
    var map = function(){
        emit(fn(this.timestamp.getYear()), 1);
    }

    // Reduce function
    var reduce = function(k, v){
        count = 0;
        for(i = 0; i < v.length; i++) {
            count += v[i];
        }
        return count;
    }

    // Javascript function available in the map reduce scope
    var t = function(val){ return val+1; }

    // Execute the map reduce with the custom scope
    var o = {};
    o.scope =  { fn: new Code(t.toString()) }
    o.out = { replace: 'replacethiscollection' }

    collection.mapReduce(map, reduce, o, function(err, outCollection) {
      test.equal(null, err);

      // Find all entries in the map-reduce collection
      outCollection.find().toArray(function(err, results) {
        test.equal(null, err);
        test.equal(2, results[0].value)

        // mapReduce with scope containing plain function
        var o = {};
        o.scope =  { fn: t }
        o.out = { replace: 'replacethiscollection' }

        collection.mapReduce(map, reduce, o, function(err, outCollection) {
          test.equal(null, err);

          // Find all entries in the map-reduce collection
          outCollection.find().toArray(function(err, results) {
            test.equal(2, results[0].value)

            db.close();
          });
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Mapreduce different test with a provided scope containing javascript objects with functions.

var MongoClient = require('mongodb').MongoClient,
  Code = require('mongodb').Code,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_scope_objects');

  // Insert some test documents
  collection.insertMany([{'user_id':1, 'timestamp':new Date()}
    , {'user_id':2, 'timestamp':new Date()}], {w:1}, function(err, r) {

    // Map function
    var map = function(){
      emit(obj.fn(this.timestamp.getYear()), 1);
    }

    // Reduce function
    var reduce = function(k, v){
      count = 0;
      for(i = 0; i < v.length; i++) {
        count += v[i];
      }
      return count;
    }

    // Javascript function available in the map reduce scope
    var t = function(val){ return val+1; }

    // Execute the map reduce with the custom scope containing objects
    var o = {};
    o.scope =  { obj: {fn: new Code(t.toString())} }
    o.out = { replace: 'replacethiscollection' }

    collection.mapReduce(map, reduce, o, function(err, outCollection) {
      test.equal(null, err);

      // Find all entries in the map-reduce collection
      outCollection.find().toArray(function(err, results) {
        test.equal(null, err);
        test.equal(2, results[0].value)

        // mapReduce with scope containing plain function
        var o = {};
        o.scope =  { obj: {fn: t} }
        o.out = { replace: 'replacethiscollection' }

        collection.mapReduce(map, reduce, o, function(err, outCollection) {
          test.equal(null, err);

          // Find all entries in the map-reduce collection
          outCollection.find().toArray(function(err, results) {
            test.equal(2, results[0].value)
            db.close();
          });
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple map reduce example using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_with_promise');

  // Insert some documents to perform map reduce over
  collection.insertMany([{'user_id':1}, {'user_id':2}], {w:1}).then(function(r) {

    // Map function
    var map = function() { emit(this.user_id, 1); };
    // Reduce function
    var reduce = function(k,vals) { return 1; };

    // Perform the map reduce
    collection.mapReduce(map, reduce, {out: {replace : 'tempCollection'}}).then(function(collection) {

      // Mapreduce returns the temporary collection with the results
      collection.findOne({'_id':1}).then(function(result) {
        test.equal(1, result.value);

        collection.findOne({'_id':2}).then(function(result) {
          test.equal(1, result.value);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple map reduce example using the inline output type on MongoDB &gt; 1.7.6 returning the statistics using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_inline_with_promise');

  // Insert some test documents
  collection.insertMany([{'user_id':1}, {'user_id':2}], {w:1}).then(function(r) {

    // Map function
    var map = function() { emit(this.user_id, 1); };
    // Reduce function
    var reduce = function(k,vals) { return 1; };

    // Execute map reduce and return results inline
    collection.mapReduce(map, reduce, {out : {inline: 1}, verbose:true}).then(function(result) {
      test.equal(2, result.results.length);
      test.ok(result.stats != null);

      collection.mapReduce(map, reduce, {out : {replace: 'mapreduce_integration_test'}, verbose:true}).then(function(result) {
        test.ok(result.stats != null);
        db.close();
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Mapreduce using a provided scope containing a javascript function executed using a Promise.

var MongoClient = require('mongodb').MongoClient,
  Code = require('mongodb').Code,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_scope_with_promise');

  // Insert some test documents
  collection.insertMany([{'user_id':1, 'timestamp':new Date()}
    , {'user_id':2, 'timestamp':new Date()}], {w:1}).then(function(r) {

    // Map function
    var map = function(){
        emit(fn(this.timestamp.getYear()), 1);
    }

    // Reduce function
    var reduce = function(k, v){
        count = 0;
        for(i = 0; i < v.length; i++) {
            count += v[i];
        }
        return count;
    }

    // Javascript function available in the map reduce scope
    var t = function(val){ return val+1; }

    // Execute the map reduce with the custom scope
    var o = {};
    o.scope =  { fn: new Code(t.toString()) }
    o.out = { replace: 'replacethiscollection' }

    collection.mapReduce(map, reduce, o).then(function(outCollection) {

      // Find all entries in the map-reduce collection
      outCollection.find().toArray().then(function(results) {
        test.equal(2, results[0].value)

        // mapReduce with scope containing plain function
        var o = {};
        o.scope =  { fn: t }
        o.out = { replace: 'replacethiscollection' }

        collection.mapReduce(map, reduce, o).then(function(outCollection) {
          // Find all entries in the map-reduce collection
          outCollection.find().toArray().then(function(results) {
            test.equal(2, results[0].value)

            db.close();
          });
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Mapreduce using a scope containing javascript objects with functions using a Promise.

var MongoClient = require('mongodb').MongoClient,
  Code = require('mongodb').Code,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_scope_objects_with_promise');

  // Insert some test documents
  collection.insertMany([{'user_id':1, 'timestamp':new Date()}
    , {'user_id':2, 'timestamp':new Date()}], {w:1}).then(function(r) {

    // Map function
    var map = function(){
      emit(obj.fn(this.timestamp.getYear()), 1);
    }

    // Reduce function
    var reduce = function(k, v){
      count = 0;
      for(i = 0; i < v.length; i++) {
        count += v[i];
      }
      return count;
    }

    // Javascript function available in the map reduce scope
    var t = function(val){ return val+1; }

    // Execute the map reduce with the custom scope containing objects
    var o = {};
    o.scope =  { obj: {fn: new Code(t.toString())} }
    o.out = { replace: 'replacethiscollection' }

    collection.mapReduce(map, reduce, o).then(function(outCollection) {

      // Find all entries in the map-reduce collection
      outCollection.find().toArray().then(function(results) {
        test.equal(2, results[0].value)

        // mapReduce with scope containing plain function
        var o = {};
        o.scope =  { obj: {fn: t} }
        o.out = { replace: 'replacethiscollection' }

        collection.mapReduce(map, reduce, o).then(function(outCollection) {
          // Find all entries in the map-reduce collection
          outCollection.find().toArray().then(function(results) {
            test.equal(2, results[0].value)
            db.close();
          });
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple map reduce example using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_with_generators');

  // Insert some documents to perform map reduce over
  yield collection.insertMany([{'user_id':1}, {'user_id':2}], {w:1});

  // Map function
  var map = function() { emit(this.user_id, 1); };
  // Reduce function
  var reduce = function(k,vals) { return 1; };

  // Perform the map reduce
  var collection = yield collection.mapReduce(map, reduce, {out: {replace : 'tempCollection'}});

  // Mapreduce returns the temporary collection with the results
  var result = yield collection.findOne({'_id':1});
  test.equal(1, result.value);
  var result = yield collection.findOne({'_id':2});
  test.equal(1, result.value);

  // Db close
  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A simple map reduce example using the inline output type on MongoDB &gt; 1.7.6 returning the statistics using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_inline_with_generators');

  // Insert some test documents
  yield collection.insertMany([{'user_id':1}, {'user_id':2}], {w:1});

  // Map function
  var map = function() { emit(this.user_id, 1); };
  // Reduce function
  var reduce = function(k,vals) { return 1; };

  // Execute map reduce and return results inline
  var result = yield collection.mapReduce(map, reduce, {out : {inline: 1}, verbose:true});
  test.equal(2, result.results.length);
  test.ok(result.stats != null);

  var result = yield collection.mapReduce(map, reduce, {out : {replace: 'mapreduce_integration_test'}, verbose:true});
  test.ok(result.stats != null);
  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Mapreduce using a provided scope containing a javascript function executed using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_scope_with_generators');

  // Insert some test documents
  yield collection.insertMany([{'user_id':1, 'timestamp':new Date()}
    , {'user_id':2, 'timestamp':new Date()}], {w:1});

  // Map function
  var map = function(){
      emit(fn(this.timestamp.getYear()), 1);
  }

  // Reduce function
  var reduce = function(k, v){
      count = 0;
      for(i = 0; i < v.length; i++) {
          count += v[i];
      }
      return count;
  }

  // Javascript function available in the map reduce scope
  var t = function(val){ return val+1; }

  // Execute the map reduce with the custom scope
  var o = {};
  o.scope =  { fn: new Code(t.toString()) }
  o.out = { replace: 'replacethiscollection' }

  // Execute with output collection
  var outCollection = yield collection.mapReduce(map, reduce, o);
  // Find all entries in the map-reduce collection
  var results = yield outCollection.find().toArray()
  test.equal(2, results[0].value);

  // mapReduce with scope containing plain function
  var o = {};
  o.scope =  { fn: t }
  o.out = { replace: 'replacethiscollection' }

  // Execute with outCollection
  var outCollection = yield collection.mapReduce(map, reduce, o);
  // Find all entries in the map-reduce collection
  var results = yield outCollection.find().toArray();
  test.equal(2, results[0].value)

  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Mapreduce using a scope containing javascript objects with functions using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a test collection
  var collection = db.collection('test_map_reduce_functions_scope_objects_with_generators');

  // Insert some test documents
  yield collection.insertMany([{'user_id':1, 'timestamp':new Date()}
    , {'user_id':2, 'timestamp':new Date()}], {w:1});

  // Map function
  var map = function(){
    emit(obj.fn(this.timestamp.getYear()), 1);
  }

  // Reduce function
  var reduce = function(k, v){
    count = 0;
    for(i = 0; i < v.length; i++) {
      count += v[i];
    }
    return count;
  }

  // Javascript function available in the map reduce scope
  var t = function(val){ return val+1; }

  // Execute the map reduce with the custom scope containing objects
  var o = {};
  o.scope =  { obj: {fn: new Code(t.toString())} }
  o.out = { replace: 'replacethiscollection' }

  // Execute returning outCollection
  var outCollection = yield collection.mapReduce(map, reduce, o);

  // Find all entries in the map-reduce collection
  var results = yield outCollection.find().toArray();
  test.equal(2, results[0].value)

  // mapReduce with scope containing plain function
  var o = {};
  o.scope =  { obj: {fn: t} }
  o.out = { replace: 'replacethiscollection' }

  // Execute returning outCollection
  var outCollection = yield collection.mapReduce(map, reduce, o);
  // Find all entries in the map-reduce collection
  var results = yield outCollection.find().toArray();
  test.equal(2, results[0].value)
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="options">
            
            options<span class="signature">(<span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1516">line 1516</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Returns the options of the collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The results callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// An example returning the options for a collection.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection that we are getting the options back from
  db.createCollection('test_collection_options', {'capped':true, 'size':1024}, function(err, collection) {
    test.equal('test_collection_options', collection.collectionName);

    // Let's fetch the collection options
    collection.options(function(err, options) {
      test.equal(true, options.capped);
      test.ok(options.size >= 1024);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example returning the options for a collection using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a test collection that we are getting the options back from
  db.createCollection('test_collection_options_with_promise', {'capped':true, 'size':1024}).then(function(collection) {
    test.equal('test_collection_options_with_promise', collection.collectionName);

    // Let's fetch the collection options
    collection.options().then(function(options) {
      test.equal(true, options.capped);
      test.ok(options.size >= 1024);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example returning the options for a collection using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a test collection that we are getting the options back from
  var collection = yield db.createCollection('test_collection_options_with_generators', {'capped':true, 'size':1024});
  test.equal('test_collection_options_with_generators', collection.collectionName);

  // Let's fetch the collection options
  var options = yield collection.options();
  test.equal(true, options.capped);
  test.ok(options.size >= 1024);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="parallelCollectionScan">
            
            parallelCollectionScan<span class="signature">(<span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2736">line 2736</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Return N number of parallel cursors for a collection allowing parallel reading of entire collection. There are<br>no ordering guarantees for returned results.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>readPreference</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="ReadPreference.html">ReadPreference</a></span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>batchSize</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Set the batchSize for the getMoreCommand when iterating over the query results.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>numCursors</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    1
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The maximum number of parallel command cursors to return (the number of returned cursors will be in the range 1:numCursors)</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>raw</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Return all BSON documents as Raw Buffer documents.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~parallelCollectionScanCallback">Collection~parallelCollectionScanCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// A parallelCollectionScan example

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var docs = [];

  // Insert some documents
  for(var i = 0; i < 1000; i++) {
    docs.push({a:i});
  }

  // Get the collection
  var collection = db.collection('parallelCollectionScan');
  // Insert 1000 documents in a batch
  collection.insertMany(docs, function(err, result) {
    var results = [];
    var numCursors = 3;

    // Execute parallelCollectionScan command
    collection.parallelCollectionScan({numCursors:numCursors}, function(err, cursors) {
      test.equal(null, err);
      test.ok(cursors != null);
      test.ok(cursors.length > 0);
      var left = cursors.length;

      for(var i = 0; i < cursors.length; i++) {
        cursors[i].toArray(function(err, items) {
          test.equal(err, null);

          // Add docs to results array
          results = results.concat(items);
          left = left - 1;

          // No more cursors let's ensure we got all results
          if(left == 0) {
            test.equal(docs.length, results.length);

            db.close();
          }
        });
      }
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A parallelCollectionScan example using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var docs = [];

  // Insert some documents
  for(var i = 0; i < 1000; i++) {
    docs.push({a:i});
  }

  // Get the collection
  var collection = db.collection('parallelCollectionScan_with_promise');
  // Insert 1000 documents in a batch
  collection.insertMany(docs).then(function(result) {
    var results = [];
    var numCursors = 3;

    // Execute parallelCollectionScan command
    collection.parallelCollectionScan({numCursors:numCursors}).then(function(cursors) {
      test.ok(cursors != null);
      test.ok(cursors.length > 0);
      var left = cursors.length;

      for(var i = 0; i < cursors.length; i++) {
        cursors[i].toArray().then(function(items) {
          // Add docs to results array
          results = results.concat(items);
          left = left - 1;

          // No more cursors let's ensure we got all results
          if(left == 0) {
            test.equal(docs.length, results.length);

            db.close();
          }
        });
      }
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// A parallelCollectionScan example using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  var docs = [];

  // Insert some documents
  for(var i = 0; i < 1000; i++) {
    docs.push({a:i});
  }

  // Get the collection
  var collection = db.collection('parallelCollectionScan_with_generators');
  // Insert 1000 documents in a batch
  yield collection.insertMany(docs);
  var results = [];
  var numCursors = 3;

  // Execute parallelCollectionScan command
  var cursors = yield collection.parallelCollectionScan({numCursors:numCursors});
  test.ok(cursors != null);
  test.ok(cursors.length >= 0);

  for(var i = 0; i < cursors.length; i++) {
    var items = yield cursors[i].toArray();
    // Add docs to results array
    results = results.concat(items);
  }

  test.equal(docs.length, results.length);
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="reIndex">
            
            reIndex<span class="signature">(<span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1779">line 1779</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Reindex all indexes on the collection<br>Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// An example showing how to force a reindex of a collection.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('shouldCorrectlyForceReindexOnCollection');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}, function(err, indexName) {

      // Force a reindex of the collection
      collection.reIndex(function(err, result) {
        test.equal(null, err);
        test.equal(true, result);

        // Verify that the index is gone
        collection.indexInformation(function(err, indexInformation) {
          test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
          test.deepEqual([ [ 'a', 1 ], [ 'b', 1 ] ], indexInformation.a_1_b_1);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example showing how to force a reindex of a collection using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  var collection = db.collection('shouldCorrectlyForceReindexOnCollection_with_promise');
  // Insert a bunch of documents for the index
  collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {w:1}).then(function(result) {

    // Create an index on the a field
    collection.ensureIndex({a:1, b:1}
      , {unique:true, background:true, w:1}).then(function(indexName) {

      // Force a reindex of the collection
      collection.reIndex().then(function(result) {
        test.equal(true, result);

        // Verify that the index is gone
        collection.indexInformation().then(function(indexInformation) {
          test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
          test.deepEqual([ [ 'a', 1 ], [ 'b', 1 ] ], indexInformation.a_1_b_1);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example showing how to force a reindex of a collection using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Create a collection we want to drop later
  var collection = db.collection('shouldCorrectlyForceReindexOnCollection_with_generators');
  // Insert a bunch of documents for the index
  yield collection.insertMany([{a:1, b:1}
    , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {w:1});

  // Create an index on the a field
  yield collection.ensureIndex({a:1, b:1}
    , {unique:true, background:true, w:1});

  // Force a reindex of the collection
  var result = yield collection.reIndex();
  test.equal(true, result);

  // Verify that the index is gone
  var indexInformation = yield collection.indexInformation();
  test.deepEqual([ [ '_id', 1 ] ], indexInformation._id_);
  test.deepEqual([ [ 'a', 1 ], [ 'b', 1 ] ], indexInformation.a_1_b_1);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="remove">
            
            remove<span class="signature">(selector, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1275">line 1275</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Remove documents.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>selector</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The selector for the update operation.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>single</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Removes the first document found.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~writeOpCallback">Collection~writeOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
        <dt class="important tag-deprecated">Deprecated</dt><dd><ul class="dummy"><li>use deleteOne, deleteMany or bulkWrite</li><ul></dd>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// An example removing all documents in a collection not using safe mode

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch a collection to insert document into
  var collection = db.collection("remove_all_documents_no_safe");
  // Insert a bunch of documents
  collection.insertMany([{a:1}, {b:2}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Remove all the document
    collection.removeMany();

    // Fetch all results
    collection.find().toArray(function(err, items) {
      test.equal(null, err);
      test.equal(0, items.length);
      db.close();
    });
  })
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example removing a subset of documents using safe mode to ensure removal of documents

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  test.equal(null, err);

  // Fetch a collection to insert document into
  var collection = db.collection("remove_subset_of_documents_safe");
  // Insert a bunch of documents
  collection.insertMany([{a:1}, {b:2}], {w:1}, function(err, result) {
    test.equal(null, err);

    // Remove all the document
    collection.removeOne({a:1}, {w:1}, function(err, r) {
      test.equal(null, err);
      test.equal(1, r.result.n);
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example removing all documents in a collection not using safe mode using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch a collection to insert document into
  var collection = db.collection("remove_all_documents_no_safe_with_promise");
  // Insert a bunch of documents
  collection.insertMany([{a:1}, {b:2}], {w:1}).then(function(result) {
    // Remove all the document
    collection.removeMany();

    // Fetch all results
    collection.find().toArray().then(function(items) {
      test.equal(0, items.length);
      db.close();
    });
  })
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example removing a subset of documents using safe mode to ensure removal of documents using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch a collection to insert document into
  var collection = db.collection("remove_subset_of_documents_safe_with_promise");
  // Insert a bunch of documents
  collection.insertMany([{a:1}, {b:2}], {w:1}).then(function(result) {
    // Remove all the document
    collection.removeOne({a:1}, {w:1}).then(function(r) {
      test.equal(1, r.result.n);
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example removing all documents in a collection not using safe mode using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Fetch a collection to insert document into
  var collection = db.collection("remove_all_documents_no_safe_with_generators");

  // Insert a bunch of documents
  yield collection.insertMany([{a:1}, {b:2}], {w:1});

  // Remove all the document
  collection.removeMany();

  // Fetch all results
  var items = yield collection.find().toArray();
  test.equal(0, items.length);
  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example removing a subset of documents using safe mode to ensure removal of documents using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Fetch a collection to insert document into
  var collection = db.collection("remove_subset_of_documents_safe_with_generators");
  // Insert a bunch of documents
  yield collection.insertMany([{a:1}, {b:2}], {w:1});
  // Remove all the document
  var r = yield collection.removeOne({a:1}, {w:1});
  test.equal(1, r.result.n);
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="rename">
            
            rename<span class="signature">(newName, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1439">line 1439</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Rename the collection.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>newName</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>New name of of the collection.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>dropTarget</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Drop the target name collection if it previously exists.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~collectionResultCallback">Collection~collectionResultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The results callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// An example of illegal and legal renaming of a collection

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Open a couple of collections
  db.createCollection('test_rename_collection', function(err, collection1) {
    db.createCollection('test_rename_collection2', function(err, collection2) {
      // Attemp to rename a collection to a number
      try {
        collection1.rename(5, function(err, collection) {});
      } catch(err) {
        test.ok(err instanceof Error);
        test.equal("collection name must be a String", err.message);
      }

      // Attemp to rename a collection to an empty string
      try {
        collection1.rename("", function(err, collection) {});
      } catch(err) {
        test.ok(err instanceof Error);
        test.equal("collection names cannot be empty", err.message);
      }

      // Attemp to rename a collection to an illegal name including the character $
      try {
        collection1.rename("te$t", function(err, collection) {});
      } catch(err) {
        test.ok(err instanceof Error);
        test.equal("collection names must not contain '$'", err.message);
      }

      // Attemp to rename a collection to an illegal name starting with the character .
      try {
        collection1.rename(".test", function(err, collection) {});
      } catch(err) {
        test.ok(err instanceof Error);
        test.equal("collection names must not start or end with '.'", err.message);
      }

      // Attemp to rename a collection to an illegal name ending with the character .
      try {
        collection1.rename("test.", function(err, collection) {});
      } catch(err) {
        test.ok(err instanceof Error);
        test.equal("collection names must not start or end with '.'", err.message);
      }

      // Attemp to rename a collection to an illegal name with an empty middle name
      try {
        collection1.rename("tes..t", function(err, collection) {});
      } catch(err) {
        test.equal("collection names cannot be empty", err.message);
      }

      // Insert a couple of documents
      collection1.insertMany([{'x':1}, {'x':2}], {w:1}, function(err, docs) {

        // Attemp to rename the first collection to the second one, this will fail
        collection1.rename('test_rename_collection2', function(err, collection) {
          test.ok(err instanceof Error);
          test.ok(err.message.length > 0);

          // Attemp to rename the first collection to a name that does not exist
          // this will be succesful
          collection1.rename('test_rename_collection3', function(err, collection2) {
            test.equal("test_rename_collection3", collection2.collectionName);

            // Ensure that the collection is pointing to the new one
            collection2.count(function(err, count) {
              test.equal(2, count);
              db.close();
            });
          });
        });
      });

    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example of illegal and legal renaming of a collection using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Open a couple of collections
  db.createCollection('test_rename_collection_with_promise').then(function(collection1) {
    db.createCollection('test_rename_collection2_with_promise').then(function(collection2) {
      // Attemp to rename a collection to a number
      try {
        collection1.rename(5, function(err, collection) {});
      } catch(err) {
        test.ok(err instanceof Error);
        test.equal("collection name must be a String", err.message);
      }

      // Attemp to rename a collection to an empty string
      try {
        collection1.rename("", function(err, collection) {});
      } catch(err) {
        test.ok(err instanceof Error);
        test.equal("collection names cannot be empty", err.message);
      }

      // Attemp to rename a collection to an illegal name including the character $
      try {
        collection1.rename("te$t", function(err, collection) {});
      } catch(err) {
        test.ok(err instanceof Error);
        test.equal("collection names must not contain '$'", err.message);
      }

      // Attemp to rename a collection to an illegal name starting with the character .
      try {
        collection1.rename(".test", function(err, collection) {});
      } catch(err) {
        test.ok(err instanceof Error);
        test.equal("collection names must not start or end with '.'", err.message);
      }

      // Attemp to rename a collection to an illegal name ending with the character .
      try {
        collection1.rename("test.", function(err, collection) {});
      } catch(err) {
        test.ok(err instanceof Error);
        test.equal("collection names must not start or end with '.'", err.message);
      }

      // Attemp to rename a collection to an illegal name with an empty middle name
      try {
        collection1.rename("tes..t", function(err, collection) {});
      } catch(err) {
        test.equal("collection names cannot be empty", err.message);
      }

      // Insert a couple of documents
      collection1.insertMany([{'x':1}, {'x':2}], {w:1}).then(function(docs) {

        // Attemp to rename the first collection to the second one, this will fail
        collection1.rename('test_rename_collection2_with_promise').then(function(err, collection) {
        }).catch(function(err) {
          test.ok(err instanceof Error);
          test.ok(err.message.length > 0);

          // Attemp to rename the first collection to a name that does not exist
          // this will be succesful
          collection1.rename('test_rename_collection3_with_promise').then(function(collection2) {
            test.equal("test_rename_collection3_with_promise", collection2.collectionName);

            // Ensure that the collection is pointing to the new one
            collection2.count().then(function(count) {
              test.equal(2, count);
              db.close();
            });
          });
        });
      });

    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// An example of illegal and legal renaming of a collection using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Open a couple of collections
  var collection1 = yield db.createCollection('test_rename_collection_with_generators');
  var collection2 = yield db.createCollection('test_rename_collection2_with_generators');
  // Attemp to rename a collection to a number
  try {
    collection1.rename(5, function(err, collection) {});
  } catch(err) {
    test.ok(err instanceof Error);
    test.equal("collection name must be a String", err.message);
  }

  // Attemp to rename a collection to an empty string
  try {
    collection1.rename("", function(err, collection) {});
  } catch(err) {
    test.ok(err instanceof Error);
    test.equal("collection names cannot be empty", err.message);
  }

  // Attemp to rename a collection to an illegal name including the character $
  try {
    collection1.rename("te$t", function(err, collection) {});
  } catch(err) {
    test.ok(err instanceof Error);
    test.equal("collection names must not contain '$'", err.message);
  }

  // Attemp to rename a collection to an illegal name starting with the character .
  try {
    collection1.rename(".test", function(err, collection) {});
  } catch(err) {
    test.ok(err instanceof Error);
    test.equal("collection names must not start or end with '.'", err.message);
  }

  // Attemp to rename a collection to an illegal name ending with the character .
  try {
    collection1.rename("test.", function(err, collection) {});
  } catch(err) {
    test.ok(err instanceof Error);
    test.equal("collection names must not start or end with '.'", err.message);
  }

  // Attemp to rename a collection to an illegal name with an empty middle name
  try {
    collection1.rename("tes..t", function(err, collection) {});
  } catch(err) {
    test.equal("collection names cannot be empty", err.message);
  }

  // Insert a couple of documents
  yield collection1.insertMany([{'x':1}, {'x':2}], {w:1});

  try {
    // Attemp to rename the first collection to the second one, this will fail
    yield collection1.rename('test_rename_collection2_with_generators');
  } catch(err) {
    test.ok(err instanceof Error);
    test.ok(err.message.length > 0);

    // Attemp to rename the first collection to a name that does not exist
    // this will be succesful
    var collection2 = yield collection1.rename('test_rename_collection3_with_generators');
    test.equal("test_rename_collection3_with_generators", collection2.collectionName);

    // Ensure that the collection is pointing to the new one
    var count = yield collection2.count();
    test.equal(2, count);
    db.close();
  }
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="replaceOne">
            
            replaceOne<span class="signature">(filter, doc, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line930">line 930</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Replace a document on MongoDB</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>filter</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The Filter used to select the document to update</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>doc</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The Document that replaces the matching document</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>upsert</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Update operation is an upsert.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>bypassDocumentValidation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allow driver to bypass schema validation in MongoDB 3.2 or higher.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~updateWriteOpCallback">Collection~updateWriteOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="save">
            
            save<span class="signature">(doc, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1311">line 1311</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Save a document. Simple full document replacement function. Not recommended for efficiency, use atomic<br>operators and update instead for more efficient operations.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>doc</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Document to save</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~writeOpCallback">Collection~writeOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
        <dt class="important tag-deprecated">Deprecated</dt><dd><ul class="dummy"><li>use insertOne, insertMany, updateOne or updateMany</li><ul></dd>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple document save with safe set to false

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch the collection
  var collection = db.collection("save_a_simple_document");
  // Save a document with no safe option
  collection.save({hello:'world'});

  // Wait for a second
  setTimeout(function() {

    // Find the saved document
    collection.findOne({hello:'world'}, function(err, item) {
      test.equal(null, err);
      test.equal('world', item.hello);
      db.close();
    });
  }, 2000);
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple document save and then resave with safe set to true

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch the collection
  var collection = db.collection("save_a_simple_document_modify_it_and_resave_it");

  // Save a document with no safe option
  collection.save({hello:'world'}, {w:1}, function(err, result) {

    // Find the saved document
    collection.findOne({hello:'world'}, function(err, item) {
      test.equal(null, err);
      test.equal('world', item.hello);

      // Update the document
      item['hello2'] = 'world2';

      // Save the item with the additional field
      collection.save(item, {w:1}, function(err, result) {

        // Find the changed document
        collection.findOne({hello:'world'}, function(err, item) {
          test.equal(null, err);
          test.equal('world', item.hello);
          test.equal('world2', item.hello2);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple document save with safe set to false using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch the collection
  var collection = db.collection("save_a_simple_document_with_promise");
  // Save a document with no safe option
  collection.save({hello:'world'});

  // Wait for a second
  setTimeout(function() {

    // Find the saved document
    collection.findOne({hello:'world'}).then(function(item) {
      test.equal('world', item.hello);
      db.close();
    });
  }, 2000);
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple document save and then resave with safe set to true using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Fetch the collection
  var collection = db.collection("save_a_simple_document_modify_it_and_resave_it_with_promise");

  // Save a document with no safe option
  collection.save({hello:'world'}, {w:1}).then(function(result) {

    // Find the saved document
    collection.findOne({hello:'world'}).then(function(item) {
      test.equal('world', item.hello);

      // Update the document
      item['hello2'] = 'world2';

      // Save the item with the additional field
      collection.save(item, {w:1}).then(function(result) {

        // Find the changed document
        collection.findOne({hello:'world'}).then(function(item) {
          test.equal('world', item.hello);
          test.equal('world2', item.hello2);

          db.close();
        });
      });
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple document save with safe set to false using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Fetch the collection
  var collection = db.collection("save_a_simple_document_with_generators");
  // Save a document with no safe option
  collection.save({hello:'world'});

  // Wait for a second
  setTimeout(function() {
    co(function*() {
      // Find the saved document
      var item = yield collection.findOne({hello:'world'});
      test.equal('world', item.hello);
      db.close();
    });
  }, 2000);
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple document save and then resave with safe set to true using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Fetch the collection
  var collection = db.collection("save_a_simple_document_modify_it_and_resave_it_with_generators");

  // Save a document with no safe option
  yield collection.save({hello:'world'}, {w:1});

  // Find the saved document
  var item = yield collection.findOne({hello:'world'})
  test.equal('world', item.hello);

  // Update the document
  item['hello2'] = 'world2';

  // Save the item with the additional field
  yield collection.save(item, {w:1});

  // Find the changed document
  var item = yield collection.findOne({hello:'world'});
  test.equal('world', item.hello);
  test.equal('world2', item.hello2);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="stats">
            
            stats<span class="signature">(<span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2169">line 2169</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Get all the collection statistics.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>scale</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Divide the returned sizes by scale value.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~resultCallback">Collection~resultCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The collection result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of retrieving a collections stats

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Crete the collection for the distinct example
  var collection = db.collection('collection_stats_test');

  // Insert some documents
  collection.insertMany([{a:1}, {hello:'world'}], {w:1}, function(err, result) {

    // Retrieve the statistics for the collection
    collection.stats(function(err, stats) {
      test.equal(2, stats.count);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of retrieving a collections stats using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Crete the collection for the distinct example
  var collection = db.collection('collection_stats_test_with_promise');

  // Insert some documents
  collection.insertMany([{a:1}, {hello:'world'}], {w:1}).then(function(result) {

    // Retrieve the statistics for the collection
    collection.stats().then(function(stats) {
      test.equal(2, stats.count);

      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of retrieving a collections stats using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Crete the collection for the distinct example
  var collection = db.collection('collection_stats_test_with_generators');

  // Insert some documents
  yield collection.insertMany([{a:1}, {hello:'world'}], {w:1});

  // Retrieve the statistics for the collection
  var stats = yield collection.stats();
  test.equal(2, stats.count);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="update">
            
            update<span class="signature">(selector, document, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1083">line 1083</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Updates documents.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>selector</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The selector for the update operation.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>document</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The update document.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>upsert</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Update operation is an upsert.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>multi</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Update one/all documents with operation.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>bypassDocumentValidation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allow driver to bypass schema validation in MongoDB 3.2 or higher.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>collation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~writeOpCallback">Collection~writeOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
        <dt class="important tag-deprecated">Deprecated</dt><dd><ul class="dummy"><li>use updateOne, updateMany or bulkWrite</li><ul></dd>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    <h5>Throws:</h5>
    
            

    <div class="param-desc">
    
        
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


    
    </div>


        
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple document update with safe set to false on an existing document using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Get a collection
  var collection = db.collection('update_a_simple_document_with_promise');

  // Insert a document, then update it
  collection.insertOne({a:1}, {w:1}).then(function(doc) {

    // Update the document with an atomic operator
    collection.updateOne({a:1}, {$set:{b:2}});

    // Wait for a second then fetch the document
    setTimeout(function() {

      // Fetch the document that we modified
      collection.findOne({a:1}).then(function(item) {
        test.equal(1, item.a);
        test.equal(2, item.b);
        db.close();
      });
    }, 1000);
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple document update using upsert (the document will be inserted if it does not exist) using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Get a collection
  var collection = db.collection('update_a_simple_document_upsert_with_promise');
  // Update the document using an upsert operation, ensuring creation if it does not exist
  collection.updateOne({a:1}, {b:2, a:1}, {upsert:true, w: 1}).then(function(result) {
    test.equal(1, result.result.n);

    // Fetch the document that we modified and check if it got inserted correctly
    collection.findOne({a:1}).then(function(item) {
      test.equal(1, item.a);
      test.equal(2, item.b);
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of an update across multiple documents using the multi option and using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Get a collection
  var collection = db.collection('update_a_simple_document_multi_with_promise');

  // Insert a couple of documentations
  collection.insertMany([{a:1, b:1}, {a:1, b:2}], {w:1}).then(function(result) {

    var o = {w:1};
    collection.updateMany({a:1}, {$set:{b:0}}, o).then(function(r) {
      test.equal(2, r.result.n);

      // Fetch all the documents and verify that we have changed the b value
      collection.find().toArray().then(function(items) {
        test.equal(1, items[0].a);
        test.equal(0, items[0].b);
        test.equal(1, items[1].a);
        test.equal(0, items[1].b);

        db.close();
      });
    })
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple document update with safe set to false on an existing document using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Get a collection
  var collection = db.collection('update_a_simple_document_with_generators');

  // Insert a document, then update it
  yield collection.insertOne({a:1}, {w:1});

  // Update the document with an atomic operator
  collection.updateOne({a:1}, {$set:{b:2}});

  // Wait for a second then fetch the document
  setTimeout(function() {
    co(function*() {
      // Fetch the document that we modified
      var item = yield collection.findOne({a:1});
      test.equal(1, item.a);
      test.equal(2, item.b);

      db.close();
    });
  }, 1000);
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple document update using upsert (the document will be inserted if it does not exist) using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Get a collection
  var collection = db.collection('update_a_simple_document_upsert_with_generators');
  // Update the document using an upsert operation, ensuring creation if it does not exist
  var result = yield collection.updateOne({a:1}, {b:2, a:1}, {upsert:true, w: 1});
  test.equal(1, result.result.n);

  // Fetch the document that we modified and check if it got inserted correctly
  var item = yield collection.findOne({a:1});
  test.equal(1, item.a);
  test.equal(2, item.b);
  db.close();
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of an update across multiple documents using the multi option and using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');

  // Get a collection
  var collection = db.collection('update_a_simple_document_multi_with_generators');

  // Insert a couple of documentations
  yield collection.insertMany([{a:1, b:1}, {a:1, b:2}], {w:1});

  var o = {w:1};
  var r = yield collection.updateMany({a:1}, {$set:{b:0}}, o);
  test.equal(2, r.result.n);

  // Fetch all the documents and verify that we have changed the b value
  var items = yield collection.find().toArray();
  test.equal(1, items[0].a);
  test.equal(0, items[0].b);
  test.equal(1, items[1].a);
  test.equal(0, items[1].b);

  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="updateMany">
            
            updateMany<span class="signature">(filter, update, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line987">line 987</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Update multiple documents on MongoDB</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>filter</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The Filter used to select the document to update</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>update</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The update operations to be applied to the document</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>upsert</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Update operation is an upsert.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~updateWriteOpCallback">Collection~updateWriteOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of an update across multiple documents using the multi option.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Get a collection
  var collection = db.collection('update_a_simple_document_multi');

  // Insert a couple of documentations
  collection.insertMany([{a:1, b:1}, {a:1, b:2}], {w:1}, function(err, result) {

    var o = {w:1};
    collection.updateMany({a:1}, {$set:{b:0}}, o, function(err, r) {
      test.equal(null, err);
      test.equal(2, r.result.n);

      // Fetch all the documents and verify that we have changed the b value
      collection.find().toArray(function(err, items) {
        test.equal(null, err);
        test.equal(1, items[0].a);
        test.equal(0, items[0].b);
        test.equal(1, items[1].a);
        test.equal(0, items[1].b);

        db.close();
      });
    })
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple updateMany operation

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('update_many');
  col.insertMany([{a:1}, {a:1}], function(err, r) {
    test.equal(null, err);
    test.equal(2, r.insertedCount);

    // Update all documents
    col.updateMany({a:1}, {$set: {b: 1}}, function(err, r) {
      test.equal(null, err);
      test.equal(2, r.matchedCount);
      test.equal(2, r.modifiedCount);

      // Finish up test
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple updateMany operation using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('update_many_with_promise');
  col.insertMany([{a:1}, {a:1}]).then(function(r) {
    test.equal(2, r.insertedCount);

    // Update all documents
    col.updateMany({a:1}, {$set: {b: 1}}).then(function(r) {
      if(r.n) {
        test.equal(2, r.n);
      } else {
        test.equal(2, r.matchedCount);
        test.equal(2, r.modifiedCount);
      }

      // Finish up test
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple updateMany operation using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Get the collection
  var col = db.collection('update_many_with_generators');
  var r = yield col.insertMany([{a:1}, {a:1}]);
  test.equal(2, r.insertedCount);

  // Update all documents
  var r = yield col.updateMany({a:1}, {$set: {b: 1}});
  test.equal(2, r.matchedCount);
  test.equal(2, r.modifiedCount);

  // Finish up test
  db.close();
});</code></pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="updateOne">
            
            updateOne<span class="signature">(filter, update, <span class="optional">options</span>, <span class="optional">callback</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line875">line 875</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Update a single document on MongoDB</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>filter</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The Filter used to select the document to update</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>update</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The update operations to be applied to the document</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Optional settings.</p>
                

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Default</th>
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>upsert</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Update operation is an upsert.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>w</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>
|

<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>wtimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    null
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The write concern timeout.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>j</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Specify a journal write concern.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>bypassDocumentValidation</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Allow driver to bypass schema validation in MongoDB 3.2 or higher.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>callback</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~updateWriteOpCallback">Collection~updateWriteOpCallback</a></span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>The command result callback</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
Promise if no callback passed
<br />

    
    
    
        <h5>Examples</h5>
        

    
    <pre class="prettyprint"><code>// Example of a simple document update with safe set to false on an existing document

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Get a collection
  var collection = db.collection('update_a_simple_document');

  // Insert a document, then update it
  collection.insertOne({a:1}, {w:1}, function(err, doc) {

    // Update the document with an atomic operator
    collection.updateOne({a:1}, {$set:{b:2}});

    // Wait for a second then fetch the document
    setTimeout(function() {

      // Fetch the document that we modified
      collection.findOne({a:1}, function(err, item) {
        test.equal(null, err);
        test.equal(1, item.a);
        test.equal(2, item.b);
        db.close();
      });
    }, 1000);
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple document update using upsert (the document will be inserted if it does not exist)

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Get a collection
  var collection = db.collection('update_a_simple_document_upsert');
  // Update the document using an upsert operation, ensuring creation if it does not exist
  collection.updateOne({a:1}, {b:2, a:1}, {upsert:true, w: 1}, function(err, result) {
    test.equal(null, err);
    test.equal(1, result.result.n);

    // Fetch the document that we modified and check if it got inserted correctly
    collection.findOne({a:1}, function(err, item) {
      test.equal(null, err);
      test.equal(1, item.a);
      test.equal(2, item.b);
      db.close();
    });
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple updateOne operation

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('update_one');
  col.updateOne({a:1}
    , {$set: {a:2}}
    , {upsert:true}, function(err, r) {
    test.equal(null, err);
    test.equal(0, r.matchedCount);
    test.equal(1, r.upsertedCount);
    // Finish up test
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple updateOne operation using a Promise.

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('update_one_with_promise');
  col.updateOne({a:1}
    , {$set: {a:2}}
    , {upsert:true}).then(function(r) {
    test.equal(0, r.matchedCount);
    test.equal(1, r.upsertedCount);
    // Finish up test
    db.close();
  });
});</code></pre>
    


    
    <pre class="prettyprint"><code>// Example of a simple updateOne operation using a Generator and the co module.

var MongoClient = require('mongodb').MongoClient,
  co = require('co');
  test = require('assert');

co(function*() {
  var db = yield MongoClient.connect('mongodb://localhost:27017/test');
  // Get the collection
  var col = db.collection('update_one_with_generators');
  var r = yield col.updateOne({a:1}
    , {$set: {a:2}}
    , {upsert:true});
  test.equal(0, r.matchedCount);
  test.equal(1, r.upsertedCount);
  // Finish up test
  db.close();
});</code></pre>
    

    
</dd>

        </dl>
    
    
    
        <h3 class="subsection-title">Type Definitions</h3>
        
        <dl>
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~bulkWriteOpCallback">
            
            bulkWriteOpCallback<span class="signature">(error, result)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line561">line 561</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for inserts</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~BulkWriteOpResult">Collection~BulkWriteOpResult</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The result object if the command was executed successfully.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~BulkWriteOpResult">BulkWriteOpResult<span class="type-signature type object">Object</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>insertedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Number of documents inserted.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>matchedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Number of documents matched for update.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>modifiedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Number of documents modified.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>deletedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Number of documents deleted.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>upsertedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Number of documents upserted.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>insertedIds</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Inserted document generated Id's, hash key is the index of the originating operation</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>upsertedIds</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Upserted document generated Id's, hash key is the index of the originating operation</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The command result object.</p></td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~collectionResultCallback">
            
            collectionResultCallback<span class="signature">(error, collection)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1422">line 1422</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for the collection method, must be used if strict is specified</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>collection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html">Collection</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The collection instance.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~countCallback">
            
            countCallback<span class="signature">(error, result)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1983">line 1983</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for results</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The count of documents that matched the query.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~deleteWriteOpCallback">
            
            deleteWriteOpCallback<span class="signature">(error, result)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1115">line 1115</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for inserts</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~deleteWriteOpResult">Collection~deleteWriteOpResult</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The result object if the command was executed successfully.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~deleteWriteOpResult">deleteWriteOpResult<span class="type-signature type object">Object</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The raw result returned from MongoDB, field will vary depending on server version.</p>
                <h6>Properties</h6>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>ok</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Is 1 if the command executed correctly.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>n</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The total count of documents deleted.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>connection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The connection object used for the operation.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>deletedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The number of documents deleted.</p></td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~findAndModifyCallback">
            
            findAndModifyCallback<span class="signature">(error, result)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2215">line 2215</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for inserts</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~findAndModifyWriteOpResult">Collection~findAndModifyWriteOpResult</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The result object if the command was executed successfully.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~findAndModifyWriteOpResult">findAndModifyWriteOpResult<span class="type-signature type object">Object</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>value</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Document returned from findAndModify command.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>lastErrorObject</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The raw lastErrorObject returned from the command.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>ok</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Is 1 if the command executed correctly.</p></td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~insertOneWriteOpCallback">
            
            insertOneWriteOpCallback<span class="signature">(error, result)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line801">line 801</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for inserts</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~insertOneWriteOpResult">Collection~insertOneWriteOpResult</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The result object if the command was executed successfully.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~insertOneWriteOpResult">insertOneWriteOpResult<span class="type-signature type object">Object</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>insertedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The total amount of documents inserted.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>ops</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Array.&lt;object></span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>All the documents inserted using insertOne/insertMany/replaceOne. Documents contain the _id field if forceServerObjectId == false for insertOne/insertMany</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>insertedId</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">ObjectId</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The driver generated ObjectId for the insert operation.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>connection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The connection object used for the operation.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The raw command result object returned from MongoDB (content might vary by server version).</p>
                <h6>Properties</h6>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>ok</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Is 1 if the command executed correctly.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>n</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The total count of documents inserted.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~insertWriteOpCallback">
            
            insertWriteOpCallback<span class="signature">(error, result)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line794">line 794</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for inserts</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~insertWriteOpResult">Collection~insertWriteOpResult</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The result object if the command was executed successfully.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~insertWriteOpResult">insertWriteOpResult<span class="type-signature type object">Object</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>insertedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The total amount of documents inserted.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>ops</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Array.&lt;object></span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>All the documents inserted using insertOne/insertMany/replaceOne. Documents contain the _id field if forceServerObjectId == false for insertOne/insertMany</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>insertedIds</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Array.&lt;ObjectId></span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>All the generated _id's for the inserted documents.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>connection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The connection object used for the operation.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The raw command result object returned from MongoDB (content might vary by server version).</p>
                <h6>Properties</h6>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>ok</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Is 1 if the command executed correctly.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>n</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The total count of documents inserted.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~parallelCollectionScanCallback">
            
            parallelCollectionScanCallback<span class="signature">(error, cursors)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line2717">line 2717</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for results</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>cursors</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Array.&lt;<a href="Cursor.html">Cursor</a>></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>A list of cursors returned allowing for parallel reading of collection.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~resultCallback">
            
            resultCallback<span class="signature">(error, result)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line1354">line 1354</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for results</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The result object if the command was executed successfully.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~updateWriteOpCallback">
            
            updateWriteOpCallback<span class="signature">(error, result)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line854">line 854</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for inserts</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~updateWriteOpResult">Collection~updateWriteOpResult</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The result object if the command was executed successfully.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~updateWriteOpResult">updateWriteOpResult<span class="type-signature type object">Object</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The raw result returned from MongoDB, field will vary depending on server version.</p>
                <h6>Properties</h6>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>ok</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>Is 1 if the command executed correctly.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>n</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The total count of documents scanned.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>nModified</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The total count of documents modified.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>connection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The connection object used for the operation.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>matchedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The number of documents that matched the filter.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>modifiedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The number of documents that were modified.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>upsertedCount</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The number of documents upserted.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>upsertedId</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The upserted id.</p>
                <h6>Properties</h6>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>_id</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">ObjectId</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The upserted _id returned from the server.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~writeOpCallback">
            
            writeOpCallback<span class="signature">(error, result)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="lib_collection.js.html">lib/collection.js</a>, <a href="lib_collection.js.html#line765">line 765</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>The callback format for inserts</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="MongoError.html">MongoError</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>An error instance representing the error during the execution.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="Collection.html#~WriteOpResult">Collection~WriteOpResult</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The result object if the command was executed successfully.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id="~WriteOpResult">WriteOpResult<span class="type-signature type object">Object</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>ops</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Array.&lt;object></span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>All the documents inserted using insertOne/insertMany/replaceOne. Documents contain the _id field if forceServerObjectId == false for insertOne/insertMany</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>connection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The connection object used for the operation.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>result</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The command result object.</p></td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

            </dl>
    
    
    
</article>

</section>  





                    <footer>
                        Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Oct 01 2018 09:50:14 GMT-0400 (EDT)
                    </footer>
                </div>
            </td>
        </tr>
    </table>
</div>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/main.js"></script>
</body>
</html>